dict
default key type should be Hashable
, not Any
#1248
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 |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
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
dict
type hint should beHashable
notAny
dict
⇝dict[Hashable, Any]
Beta Was this translation helpful? Give feedback.
All reactions