-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve dict
's constructor type
#8517
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
Conversation
Please note the comments on lines 1017-1018 :) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some test cases for the various exotic ways of constructing a dict
that the stub is trying to account for? 6 overloads is frying my brain a little :(
This comment has been minimized.
This comment has been minimized.
Looks like pyright does a lot of quite different things to mypy in terms of |
What should we do in this case? All mypy tests pass, but |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
🤣 |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
I think I finally solved it! 🎉 I think in the future we can end up doing something like the runtime does: >>> i = [(1, True)]
>>> dict(i, arg=1.5)
{1: True, 'arg': 1.5} Probably like: class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __init__(self: dict[_KT | str, _VT | _NVT], __iterable: Iterable[tuple[_KT, _VT]], **kwargs: _NVT) -> None: ... But, this will be very major change! This 100% needs proper discussion. For now, I consider this PR complete 🙂 |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooray!
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This is quite hard. So, let me explain.
Right now when doing something like this:
mypy has to special-case this check. Which is not good.
I think this can be easily expressed by the type-system itself.