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
patch.dict(x, y) interpreted as invoking __call__, not __init__ #5118
Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
I think this is a mypy bug, happy to be sent to typeshed though.
I'm using mypy 0.6, and have the following code:
from unittest import TestCase
from unittest.mock import patch
class A(TestCase):
@patch.dict("os.environ", {"PATH": os.path.expanduser("~/.local/bin")})
@patch.object(moduleA, "a")
@patch("subprocess.check_output")
def test_missing(self, check_output, a):
pass
This errors like so: error: Too many arguments for "__call__" of "_patch_dict"
So mypy should be able to tell that this is instantiating an instance of _patch_dict with __init__ and then that instance is being called with one argument - the curried patcher next inwards in the stack.
changed the title [-]patch.dict interpreted as __call__ not __init__[/-][+]patch.dict(x, y) interpreted as invoking __call__, not __init__[/+]on May 29, 2018
I think this is a bug in the stubs. patch.dict is the _patch_dict class itself, not an instance of _patch_dict, so the annotation should be # type: Type[_patch_dict], not # type: _patch_dict.
Activity
[-]patch.dict interpreted as __call__ not __init__[/-][+]patch.dict(x, y) interpreted as invoking __call__, not __init__[/+]li-dan commentedon May 29, 2018
I think this is a bug in the stubs.
patch.dictis the_patch_dictclass itself, not an instance of_patch_dict, so the annotation should be# type: Type[_patch_dict], not# type: _patch_dict.gvanrossum commentedon May 29, 2018
Can one of you submit a PR to typeshed?
rbtcollins commentedon May 29, 2018
Let me give it a spin
rbtcollins commentedon May 29, 2018
Should we also wrap dict in ClassVar ?
JelleZijlstra commentedon May 29, 2018
I think you can just do
dict = _patch_dict; haven't tested though.rbtcollins commentedon May 29, 2018
python/typeshed#2173
rbtcollins commentedon May 30, 2018
@JelleZijlstra you can in Python 3; for some reason that fails on Python 2 (see the typeshed CI job).