You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No overload variant of "fromkeys" of "dict" matches argument types [typing.Iterable[Any], Union[Any, def (*Any, **Any) -> Any]] #2254
and this give me the following error : No overload variant of "fromkeys" of "dict" matches argument types [typing.Iterable[Any], Union[Any, def (_Any, *_Any) -> Any]]
Thanks for the question! I'd be happy to help but I'm not sure I understand the context of that definition. Can you show a complete, small, self-contained program that exhibits this behavior?
Oh, it seems you've hit two issues! When I run that example I get:
__tmp__.py: note: In class "DictWrapper":
__tmp__.py:6: error: Signature of "fromkeys" incompatible with supertype "dict"
__tmp__.py: note: In member "fromkeys" of class "DictWrapper":
__tmp__.py:9: error: No overload variant of "fromkeys" of "dict" matches argument types [typing.Iterable[Any], Union[Any, def (*Any, **Any) -> Any]]
(Line 6 is the def, line 9 is the super() call.)
The first complaint is because in typeshed, fromkeys() is defined as a static method, while it is actually a class method. I don't know why this is, but I think I can just fix that.
The second complaint is probably because mypy doesn't understand callable(value) and hence it doesn't believe that the value you pass to the superclass version of fromkeys() matches the required type. This is issue #1973.
My recommendation is to add a # type: ignore to the offending line and proceed.
OK then I think I have fixed both issues and this can be closed. @trnsnt, to get the fix right away you'll have to pull down the mypy repo, git submodule update, and then in the typeshed subdir do something like "git co master; git pull".
Activity
gvanrossum commentedon Oct 14, 2016
Thanks for the question! I'd be happy to help but I'm not sure I understand the context of that definition. Can you show a complete, small, self-contained program that exhibits this behavior?
trnsnt commentedon Oct 14, 2016
Hello, thanks for the reply. Here is what I have done.
I have this class
Code is working fine (Python 3.5), but when I run mypy, I have the following error :
I am not sure if it is a problem, or if I have done something wrong.
gvanrossum commentedon Oct 14, 2016
Oh, it seems you've hit two issues! When I run that example I get:
(Line 6 is the
def, line 9 is thesuper()call.)The first complaint is because in typeshed,
fromkeys()is defined as a static method, while it is actually a class method. I don't know why this is, but I think I can just fix that.The second complaint is probably because mypy doesn't understand
callable(value)and hence it doesn't believe that thevalueyou pass to the superclass version offromkeys()matches the required type. This is issue #1973.My recommendation is to add a
# type: ignoreto the offending line and proceed.Make dict.fromkeys() a classmethod (which it is).
rwbarton commentedon Oct 14, 2016
Isn't the second error just because you passed an
Iterable, butdict.fromkeysexpects aSequence?Make dict.fromkeys() a classmethod (which it is). (#604)
gvanrossum commentedon Oct 14, 2016
Oh, good catch! I will fix that at the same time. Wait for the next iteration of python/typeshed#604.
Make fromkeys() take an Iterable instead of a sequence. (#605)
gvanrossum commentedon Oct 14, 2016
OK then I think I have fixed both issues and this can be closed. @trnsnt, to get the fix right away you'll have to pull down the mypy repo, git submodule update, and then in the typeshed subdir do something like "git co master; git pull".
gvanrossum commentedon Oct 15, 2016
Sadly making fromkeys() a classmethod breaks, due to #328, so this is not fixed. Really sorry!! I went too fast here.
gvanrossum commentedon Oct 15, 2016
(And this is not a duplicate of that issue -- there's the separate problem that Reid pointed out about the real fromkeys() taking an Iterable.)
gvanrossum commentedon Oct 20, 2016
Keeping this open until #328 is fixed and typeshed has been updated.
JelleZijlstra commentedon Mar 19, 2022
Seems like this is fixed. This variation of the OP's post:
produces no errors on current mypy