-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Unions that include Any should probably not just become Any #1642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What's the real example where you got this? ISTM that if a value can be Any then mypy should shut up about it, not try to be picky. If we consider a type to be a set of values, then Any is the set of all values, so adding strings to it doesn't do anything. |
I think I wasn't directly bitten by this, but I realized this was a bit fishy while I was reviewing #1639. |
Hm... The situation in #1639 is a little different. The expression in the except clause must be either an exception or a tuple of exceptions, but it cannot be a tuple of tuples of exceptions. So it is incorrect to treat it as a union, and the code is right to insist that each individual value in the tuple is compatible with BaseException -- not that the tuple as a whole (or the tuple turned into a union) is compatible with BaseException. I still don't think that from your original example above it follows that You can still use |
Preserving |
Let's close this issue then. |
I've since seen this issue in user code, and we're more agreed on this being a good idea. Reopening so we don't forget about this. |
Should probably also be brought up in the python/typing tracker. |
This was implemented a while ago. |
Uh oh!
There was an error while loading. Please reload this page.
Currently,
UnionType.make_simplified_union
will return an Any if any of the types passed in are Any. This probably doesn't make sense.As a simple example, if we have:
(This example looks a little silly, but this
Any
might not be explicit -- it could e.g. be a class from a --silent-imports module.)This is clearly unsafe. I think we should still require an isinstance check.
The text was updated successfully, but these errors were encountered: