Skip to content

AsyncMock stubs for mypy in Python 3.7 #500

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

Closed
GDYendell opened this issue Aug 19, 2021 · 5 comments
Closed

AsyncMock stubs for mypy in Python 3.7 #500

GDYendell opened this issue Aug 19, 2021 · 5 comments

Comments

@GDYendell
Copy link

GDYendell commented Aug 19, 2021

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)
@GDYendell GDYendell changed the title AsyncMock stubs for mypy AsyncMock stubs for mypy in Python 3.7 Aug 19, 2021
@cjw296
Copy link
Collaborator

cjw296 commented Aug 21, 2021

Hi! I think the right way to do this would be to just add the type annotations you need upstream (ie: as a CPython PR) and then they will flow down to the backport here.

If you create such a PR, feel free to link it from this issue.

@GDYendell
Copy link
Author

GDYendell commented Aug 23, 2021

Thanks @cjw296. There are stubs specifically for this package here, but they had the same type checks as the stdlib version here. I have just had a PR merged to fix this.

@cjw296
Copy link
Collaborator

cjw296 commented Aug 24, 2021

You're missing my point: there's no need for separate type stubs, please add typing information you need as a PR to the actual code upstream, so that no separate stubs are needed.

(Unless I'm missing something: my understanding is that type stubs were only intended to be a stop-gap until the source code could have type annotations added to it, if you know different, please explain it to me!)

Also, your link to https://github.com/python/typeshed/blob/master/stubs/mock/mock.pyi gives me a 404.

@GDYendell
Copy link
Author

GDYendell commented 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.

@cjw296
Copy link
Collaborator

cjw296 commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants