Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JukkaL opened this issue Sep 5, 2019 · 3 comments
Closed

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

JukkaL opened this issue Sep 5, 2019 · 3 comments
Labels
stubs: false positive Type checkers report false errors

Comments

@JukkaL
Copy link
Contributor

JukkaL commented Sep 5, 2019

#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.

@srittau
Copy link
Collaborator

srittau commented Sep 5, 2019

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

@srittau srittau added size-small stubs: false positive Type checkers report false errors labels Oct 11, 2019
@srittau
Copy link
Collaborator

srittau commented Oct 13, 2019

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

srittau added a commit to srittau/typeshed that referenced this issue Oct 13, 2019
Currently this is just an alias for Any like Mock and MagicMock. All of
these classes should probably be sub-classing Any and add their own
methods. See also python#3224.
srittau added a commit that referenced this issue Oct 14, 2019
* Add os.add_dll_directory()
* Add memfd_create() and flags
* Add type annotation to flags
* Add stat_result.st_reparse_tag and flags
* Add ncurses_version
* Add Path.link_to()
* Add Picker.reducer_override()
* Add plistlib.UID
* Add has_dualstack_ipv6() and create_server()
* Add shlex.join()
* Add SSL methods and fields
* Add Python 3.8 statistics functions and classes
* Remove obsolete sys.subversion
* Add sys.unraisablehook
* Add threading.excepthook
* Add get_native_id() and Thread.native_id
* Add Python 3.8 tkinter methods
* Add CLOCK_UPTIME_RAW
* Add SupportsIndex
* Add typing.get_origin() and get_args()
* Add unicodedata.is_normalized
* Add unittest.mock.AsyncMock

Currently this is just an alias for Any like Mock and MagicMock. All of
these classes should probably be sub-classing Any and add their own
methods. See also #3224.

* Add unittest cleanup methods
* Add IsolatedAsyncioTestCase
* Add ElementTree.canonicalize() and C14NWriterTarget
* cProfile.Profile can be used as a context manager
* Add asyncio task name handling
* mmap.flush() now always returns None
* Add posonlyargcount to CodeType
@hauntsaninja
Copy link
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
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

No branches or pull requests

3 participants