You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New semantic analyzer: conditionally defined functions #6318
Support conditionally defined functions was dropped at some point when implementing the early versions of the new semantic analyzer. It's probably worth implementing this from scratch since the old implementation was pretty messy.
This issue applies to functions where multiple definitions are considered reachable by mypy. Cases involving platform and Python version checks where only one implementation is reachable already work. Example where this applies:
ifcond(): # Condition determined at runtime!deffoo() ->None:
... # something; will be checkedelse:
deffoo() ->None:
... # something else; will also be checked
A clean solution for this may be non-trivial. In general we might need to switch from node.node to node.nodes, this will also allow us to support conditional definition of variables, conditional imports etc., but this is a big change. It seems to me there is a whole bunch of issues around conditional definitions and it would make sense to discuss/fix them together.
Activity
ilevkivskyi commentedon Feb 4, 2019
A clean solution for this may be non-trivial. In general we might need to switch from
node.nodetonode.nodes, this will also allow us to support conditional definition of variables, conditional imports etc., but this is a big change. It seems to me there is a whole bunch of issues around conditional definitions and it would make sense to discuss/fix them together.JukkaL commentedon Feb 4, 2019
I was thinking of just cleaning up the implementation a bit now, without changing their behavior or general implementation strategy.
ilevkivskyi commentedon Feb 17, 2019
We also will need to support something like this:
This is supported by old analyzer, and there are examples of this in our internal code (currently this causes a crash).
New semantic analyzer: conditional function definitions (#6429)