typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

mock.patch.object type annotation fails with **kwargs

Open graingert opened this issue 3 years ago • 1 comments

https://mypy-play.net/?mypy=latest&python=3.10&gist=6f7d6d1036646b8e8a41ed3a5dab3b98&flags=strict

from unittest import mock
import subprocess


def foo() -> None:
    with mock.patch.object(
        subprocess,
        "Popen",
        **{"return_value.communicate.side_effect": KeyboardInterrupt}
    ):
        pass

graingert avatar Mar 24 '22 10:03 graingert

mock.patch.object() should probably be marked as a staticmethod in the stubs. (The same for dict(), multiple(), and stopall().)

srittau avatar Mar 24 '22 11:03 srittau

Reopening as per https://github.com/python/typeshed/pull/7543#pullrequestreview-1123222530 -- the original snippet still causes mypy to emit a false-positive error, even using mypy master and typeshed master.

AlexWaygood avatar Nov 01 '22 12:11 AlexWaygood