-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Revert "Fixing signature for Mapping.get's default parameter" #2817
Conversation
This reverts commit 3f83195.
The tests will likely fail because of an update in mypy tests, I will revert that now, and then re-run the tests here. |
Off topic, but this is one example why having a test suite for typeshed is a good idea. This could be used to test and document the reason why certain typings are as they are. |
I'm OK with reverting. I'd like to hear more from the Pyre team on why they thought this change was necessary though. |
The problem with this signature is that it results in a unbound type variable in the return type in the case of the default parameter coinciding with the value type of the mapping. Does mypy just drop elements with unbound type variables from unions in returns? Arguably the other solution here is to keep my change and to allow literal empty lists to subclass any defined list (which is what pyre does, but currently in too many places) and thus collapse that union. |
Mypy infers
And how this can be put into the type system? Should we just special-case lists, what to do with user-defined generic collections? TBH, I don't think this is a good idea. Unless this will cause some immediate troubles for you, I will merge this since it already causes troubles for us, otherwise I think we can wait couple days. |
What we're doing is allowing |
Hm, actually mypy also bans assigning |
This reverts commit 759ff9f. Reverts #6469 See python/typeshed#2817 for motivation.
Sure, we can work around it, but I think it'd be worth considering allowing that special case exception to subclassing before changing werkzeug as well. |
OK |
Reverts #2810. cc @mrkmndz
#2810 causes significant troubles in real code. Consider this example:
This used to produce
builtins.list[builtins.str]
but now it producesUnion[builtins.list[builtins.str], builtins.list[<nothing>]]
causing subsequent failures because of invariance.The old signature provided type context for inference of the default argument, and was not wrong in any sense.
@mrkmndz Potentially we might need to do the same for
werkzeug.datastructures.TypeConversionDict
andwerkzeug.datastructures.Headers
, since this type signature is better for type inference.