AsyncMock stubs for mypy in Python 3.7
See original GitHub issueIs there an equivalent to the stubs for the standard library version of mock for this package?
I am using AsyncMock in python 3.7 with this package and it works fine, but the stubs are not defined for AsyncMock in the package above, so mypy is giving errors. Is there a solution to this besides updating to 3.8+ and using unittest.mock?
▶ mypy tests/
tests/test_odinprocserv.py:2: error: Module "mock" has no attribute "AsyncMock"
tests/test_odinprocserv.py:43: error: "Callable[[], Coroutine[Any, Any, None]]" has no attribute "assert_awaited_once_with"
tests/test_odinprocserv.py:53: error: "Callable[[], Coroutine[Any, Any, None]]" has no attribute "assert_not_called"
tests/test_odinprocserv.py:63: error: "Callable[[], Any]" has no attribute "assert_called_once_with"
tests/test_odinprocserv.py:73: error: "Callable[[], Any]" has no attribute "assert_not_called"
tests/test_odinprocserv.py:83: error: "Callable[[], Coroutine[Any, Any, None]]" has no attribute "assert_called_once_with"
tests/test_odinprocserv.py:93: error: "Callable[[], Coroutine[Any, Any, None]]" has no attribute "assert_not_called"
tests/test_odinprocserv.py:161: error: "Callable[[List[str], str], Coroutine[Any, Any, None]]" has no attribute "await_args_list"
Found 8 errors in 1 file (checked 2 source files)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Stub files - mypy 0.991 documentation
Mypy uses stub files stored in the typeshed repository to determine the types of standard library and third-party library functions, classes, ...
Read more >python/typing - Gitter
Mypy supports custom sentinel types using single-valued enums ... are no different from third party modules, if there are no stubs in typeshed...
Read more >MyPy Cannot Find Library Stubs for Specific Python Version
When I run a nox session to run mypy against the code, the Python 3.7 check complains about mypy not being able to...
Read more >Mocking Asynchronous Functions In Python - dino (dot) codes
You might have already heard about Python's asyncio module, ... functions by leveraging Futures in Python 3.7 and AsyncMock in Python 3.8 ...
Read more >django-stubs - PyPI
Mypy stubs for Django. ... Note: This monkey patching approach will only work when using Python 3.7 and higher, when the __class_getitem__ magic...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

To be clear: I think shipping separate stubs is a really bad idea for any python package, and I was strongly against that part of the PEP. They will invariably get out of date and cause more problems than they solve.
Sorry, I fixed the link.
What I mean is the stubs already existed and needed a small fix to solve the problem. I was wondering why the type annotations aren’t already added to cpython, as it is much better for developing against. I am interested in doing that, but it will require significantly more effort and probably be a more drawn out review process to make sure nothing is broken.