dict default key type should be Hashable, not Any
#1248
randolf-scholz
started this conversation in
General
Replies: 2 comments
|
Unspecified type arguments default to While it is allowed to leave type arguments unspecified, it is not recommended. In other words, you generally shouldn't use a "bare" There is a draft PEP that proposes to add support for default type arguments, but even with this new facility, it wouldn't make sense to default the first type parameter of |
0 replies
|
Just curious, but when would this matter? mypy doesn't report any problem on line 3 of the following code for me: d: dict = {}
for k in d:
hash(k) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Python dictionaries raise a runtime-error when fed a non-hashable object. Therefore, the default key-type of a blank
dicttype hint should beHashablenotAnydict⇝dict[Hashable, Any]All reactions