question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncMock stubs for mypy in Python 3.7

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
cjw296commented, Aug 24, 2021

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.

0reactions
GDYendellcommented, Aug 24, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found