Skip to content

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

Open

Description

@graingert

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

Activity

  1. srittau commented on Mar 24, 2022

    @srittau
    Collaborator

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

  2. added a commit that references this issue on Mar 24, 2022
    f49ec6c
  3. AlexWaygood commented on Nov 1, 2022

    @AlexWaygood
    Member

    Reopening as per #7543 (review) -- the original snippet still causes mypy to emit a false-positive error, even using mypy master and typeshed master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions