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

Mark as PEP 561 (type checking) compatible #439

Closed
huonw opened this issue Dec 1, 2020 · 0 comments · Fixed by #440
Closed

Mark as PEP 561 (type checking) compatible #439

huonw opened this issue Dec 1, 2020 · 0 comments · Fixed by #440

Comments

@huonw
Copy link
Contributor

huonw commented Dec 1, 2020

Is your feature request related to a problem? Please describe.

MyPy and other static type checkers are helpful for validating code. Currently syrupy doesn't work perfectly in projects that use mypy, because it is not considered PEP 561 compatible: https://mypy.readthedocs.io/en/latest/installed_packages.html#making-pep-561-compatible-packages

This means that something like:

# syrupy-typing.py
from syrupy.assertion import SnapshotAssertion

def test_foo(snapshot: SnapshotAssertion) -> None:
    assert "foo" == snapshot(match="x")

fails with

syrupy-typing.py:2: error: Skipping analyzing 'syrupy': found module but no type hints or library stubs
    from syrupy import SnapshotAssertion
    ^
syrupy-typing.py:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports

The fix for users for this is ignoring the imports (as described in the link there), such as from syrupy.assertion import SnapshotAssertion # type: ignore. However, this is unfortunate because it stops mypy and potentially other tooling from picking up the error: match instead of matcher.

Describe the solution you'd like

By adding a py.typed file as described in https://mypy.readthedocs.io/en/latest/installed_packages.html#making-pep-561-compatible-packages , the existing type annotations become available to mypy users.

The output of the above then becomes:

syrupy-typing.py:5: error: Unexpected keyword argument "match" for "__call__" of "SnapshotAssertion"; did you mean "matcher"?
        assert "foo" == snapshot(match="x")
                        ^

Describe alternatives you've considered

A separate stub file/project seems unnecessary, given there's already type annotations inline in the code.

Additional context

N/A

huonw added a commit to huonw/syrupy that referenced this issue Dec 1, 2020
This follows PEP-561 to mark syrupy as compatible with type
checking (driven by the type annotations that already exist and are
checked), by creating an empty `py.typed` in the project. This stops
users from having to ignore syrupy when type checking, and allows the
type checker to provide specific guidance about possible problems.

Fixes syrupy-project#439
noahnu pushed a commit that referenced this issue Dec 1, 2020
* feat: add PEP-561 py.typed file for downstream type checkers

This follows PEP-561 to mark syrupy as compatible with type
checking (driven by the type annotations that already exist and are
checked), by creating an empty `py.typed` in the project. This stops
users from having to ignore syrupy when type checking, and allows the
type checker to provide specific guidance about possible problems.

Fixes #439
syrupy-bot pushed a commit that referenced this issue Dec 1, 2020
# [1.1.0](v1.0.0...v1.1.0) (2020-12-01)

### Features

* add PEP-561 py.typed file for downstream type checkers ([#440](#440)) ([fe15bdb](fe15bdb)), closes [#439](#439)
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

Successfully merging a pull request may close this issue.

1 participant