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
It seems like this can get complex pretty quickly (imagine using tuples inside an and, now you effectively have an intersection of unions). Theres so many cases to cover that I'm thinking about just going all-out here and writing an all-encompassing solution.
I've been toying with converting the expressions to DNF and seeing if we can just do an all-encompassing solution that way but I'm not confident in its correctness since it effectively makes complicated cases just as difficult as simple cases.
In general, if in doubt whether a particular idiom or construct is worth supporting, try to find actual examples of that in some existing projects. If you can't find any (or just find a few isolated examples), it's probably not that important, and there are lot of things that mypy can't deal with that we know to be important (such as every issue tagged with 'priority').
Activity
JukkaL commentedon Oct 17, 2015
Yes, that would be nice. #947 is related (tuple as the second argument to
isinstance).jhance commentedon Oct 18, 2015
It seems like this can get complex pretty quickly (imagine using tuples inside an
and, now you effectively have an intersection of unions). Theres so many cases to cover that I'm thinking about just going all-out here and writing an all-encompassing solution.I've been toying with converting the expressions to DNF and seeing if we can just do an all-encompassing solution that way but I'm not confident in its correctness since it effectively makes complicated cases just as difficult as simple cases.
JukkaL commentedon Oct 18, 2015
At this point it's okay to add some limitations, such as for
andall the operands must target different variables. So this wouldn't work correctly:(we'd only recognize the first
isinstance, since mypy doesn't support intersection types)We can revisit this later, but the complex cases are going to be pretty marginal so it's not worth it to complicate everything because of them.
JukkaL commentedon Oct 18, 2015
In general, if in doubt whether a particular idiom or construct is worth supporting, try to find actual examples of that in some existing projects. If you can't find any (or just find a few isolated examples), it's probably not that important, and there are lot of things that mypy can't deal with that we know to be important (such as every issue tagged with 'priority').
Use isinstance information when type checking 'or' expressions
Support `or` in `isinstance` checks
Support `or` in `isinstance` checks
Use isinstance information when type checking 'or' expressions (#1709)
Support `or` in `isinstance` checks
Support `or` in `isinstance` checks (#1712)