-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Overloads defined for None and object get inferred as Any #3757
Comments
Thanks for reporting the issue! This is a duplicate of #3256. |
Hmm, really? Without much knowledge of the underlying machinery, that seems surprising to me--#3256 is only a problem without strict-optional, and this test case only makes sense with strict-optional enabled. Also, this seems to have to do with some kind of special-casing of Sorry if there's some deeper reason I'm missing as to why they're actually the same! I'm interested in knowing because I was planning to try to fix this today :) |
Hmm, ok, it appears to actually be intentional that if isinstance(actual, NoneTyp):
if not experiments.STRICT_OPTIONAL:
# NoneTyp matches anything if we're not doing strict Optional checking
return 2
else:
# NoneType is a subtype of object
if isinstance(formal, Instance) and formal.type.fullname() == "builtins.object":
return 2 I made a branch changing the |
Hey @ilinum or anyone else, wondering whether you have feedback on whether this is truly a duplicate, or whether my proposal (or something like it) seems like a good resolution? |
Sorry, I was away for the weekend, so didn't see your comments until just now. Yep, you're right this is not a duplicate of the #3256. I missed the fact that your example fails with Your fix seems reasonable, I think it could work. It's probably worth sending a PR and seeing what other say. |
Oops, wrong place, deleting the comment. |
Update: The original example still won't typecheck (by design), but we recently added code to master that special-cases and allows this kind of overload for specifically descriptors -- see #5093 for examples. So, I think we can probably close this now? Feel free to reopen if anybody disagrees. |
(This came up while playing with descriptors, where the first parameter of
__get__
can be eitherNone
or an arbitrary object and you want different return types in the two cases.)Example reproduction using
mypy --strict-optional
on 0.520:The text was updated successfully, but these errors were encountered: