Skip to content

isinstance(x, mock.Mock) is broken since Mock is aliased to Any #3224

Closed

Description

@JukkaL

#3182 changed mock.Mock to be an alias to Any, which resulted in mypy complaining about isinstance(x, mock.Mock), which I believe should be valid.

We can fix this by reverting #3182 or potentially by making Mock a class with an Any base class. Mock is a class at runtime, so making it an alias to Any (which is not a class) seems wrong to me.

Activity

  1. srittau commented on Sep 5, 2019

    @srittau
    Collaborator

    Subclassing sounds to be the best solution to me, if it works. That also means we could add methods to it, which exist on the implementation. Cc @JelleZijlstra

  2. added
    stubs: false positive
    on Oct 11, 2019
  3. srittau commented on Oct 13, 2019

    @srittau
    Collaborator

    Also MagicMock and AsyncMock (when my Python 3.8 patch gets merged).

  4. hauntsaninja commented on Jun 11, 2020

    @hauntsaninja
    Collaborator

    I believe this is fixed by #3846 and others

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

    stubs: false positive

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions