10000 patch.dict(x, y) interpreted as invoking __call__, not __init__ · Issue #5118 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content
patch.dict(x, y) interpreted as invoking __call__, not __init__ #5118
Closed
@rbtcollins

Description

@rbtcollins

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"

The typeshed stub for this is

    class _patch_dict:
...
        def __init__(self, in_dict: Any, values: Any = ..., clear: Any = ..., **kwargs: Any) -> None: ...
        def __call__(self, f: Any) -> Any: ...
...

    class _patcher:
        TEST_PREFIX = ...  # type: str
        dict = ...  # type: _patch_dict
...
    patch = ...  # type: _patcher

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0