-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
return Hashable from functools._make_key #5385
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
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Nope, it returns either >>> from functools import _make_key
>>> _make_key(('aa'),{},False)
['a', 'a']
>>> type(_make_key(('aa'),{},False))
<class 'functools._HashedSeq'>
>>> _make_key((1,),{'a':'b'},False )
[1, <object object at 0x7fbc462daeb0>, 'a', 'b']
>>> type(_make_key((1,),{'a':'b'},False ))
<class 'functools._HashedSeq'>
# if len(args) == 1 and type(key[0]) in fasttypes, it returns one of the fasttypes: {int,str} which is hashable
>>> _make_key(('a'),{},False)
'a'
>>> type(_make_key(('a'),{},False))
<class 'str'>
>>> _make_key(([1]),{},False)
1
>>> type(_make_key(([1]),{},False))
<class 'int'> |
|
Well, it turns out to be hashable, but I thought maybe it inherits from >>> from collections.abc import Hashable
>>> isinstance(_make_key((1,),{'a':'b'},False ), Hashable)
True Nice catch! |
Maybe the |
At the end of the day, I think no one would like to annotate a variable like: key: _HashedSeq = _make_key(args, kwargs, False ) But rather:
However, giving the programmer more options would be kind. |
If you need the key to be a
In general, we support |
#5370 added
functools._make_key
. Its purpose is to return a hashable object to representargs
andkwargs
, so even though it returns two different things, returningHashable
works in both cases.@Harmouch101 What do you think?