Skip to content

add type annotations #152

Closed
Closed

Description

@chdsbd

I think it may be helpful to add type annotations to this package.

Activity

  1. nicoddemus commented on Aug 2, 2019

    @nicoddemus
    Member

    Thanks for the suggestion @chdsbd. I think this would be best when pytest-mock supports Python 3 only so we can use native type annotations.

  2. JakeSummers commented on Apr 2, 2020

    @JakeSummers

    There are some reasonable workarounds to this problem.

    Right now I have a test like this:

    def test_car(mocker: MockFixture):
        mocker.patch.object(Engine, "run")
        car = Car()
        car.start()
        Engine.run.assert_any_call(... )
    

    When I run it through mypy, I get the following error:

    test_car.py:30: error: "Callable[[Engine, ...], ...]" has no attribute "assert_any_call"
    

    Workaround #1 - Ignore the error

    def test_car(mocker: MockFixture):
        mocker.patch.object(Engine, "run")
        car = Car()
        car.start()
        Engine.run.assert_any_call(... ) # ignore: type
    

    Workaround #2 - Use the result of the patch command.

    def test_car(mocker: MockFixture):
        engine_mock:MagicMock = mocker.patch.object(Engine, "run")
        car = Car()
        car.start()
        engine_mock.assert_any_call(... ) # ignore: type
    
  3. srittau commented on Jun 26, 2020

    @srittau
    Contributor

    FWIW, I have just opened python/typeshed#4275. This will add stubs to typeshed for now. Of course, I'd be glad to see the stubs in pytest-mock directly some day, either via separate stub files or inline.

  4. bluetech commented on Jun 26, 2020

    @bluetech
    Member

    @srittau What gets priority when a package has its own stubs, and is also defined in typeshed?

  5. JelleZijlstra commented on Jun 28, 2020

    @JelleZijlstra
  6. bluetech commented on Jun 28, 2020

    @bluetech
    Member

    Thanks @JelleZijlstra. So it should be fine if we ever decide to ship type annotations inline.

  7. srittau commented on Jun 28, 2020

    @srittau
    Contributor

    As soon as that happens, we should remove the stubs from typeshed anyway, to avoid confusion and reduce typeshed's maintenance burden.

  8. jtpavlock commented on Aug 6, 2020

    @jtpavlock

    Pytest 6.0 now supports type annotations and pytest-mock is now python3.5+ 👀

  9. nicoddemus commented on Aug 6, 2020

    @nicoddemus
    Member

    In #194 we now run mypy without errors on pytest-mock itself (thanks to @staticdev), so at least that step is done.

    The next step would probably be to type annotate the public API and export a py.typed file along the package.

  10. added a commit that references this issue on Aug 22, 2020
    2344070
  11. added a commit that references this issue on Aug 24, 2020
  12. added a commit that references this issue on Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions