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

Update typing syntax and usage for Python 3.6+ #535

Merged
merged 1 commit into from
Dec 16, 2020
Merged

Update typing syntax and usage for Python 3.6+ #535

merged 1 commit into from
Dec 16, 2020

Conversation

jdufresne
Copy link
Contributor

Now that Python 2 is not supported, can move away from type comments to
type annotation 🎉.

The typing module is always available, so remove the guards.

Specify the supported Python in the mypy configuration.

Move other mypy configurations to one place. This way, whether tox is
used or not, the same mypy errors appear.

Distribute and install PEP-561 compliant py.typed file. When PyJWT is a
imported as a library, this tells mypy to use the provided type
annotations rather than going through typeshed. This way, the types are
always up to date when running mypy.

Remove outdated ignores since dropping Python 2.

Copy link
Owner

@jpadilla jpadilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdufresne thank you for this! q: is that jwt/py.typed file supposed to be empty?

Now that Python 2 is not supported, can move away from type comments to
type annotation 🎉.

The typing module is always available, so remove the guards.

Specify the supported Python in the mypy configuration.

Move other mypy configurations to one place. This way, whether tox is
used or not, the same mypy errors appear.

Distribute and install PEP-561 compliant py.typed file. When PyJWT is a
imported as a library, this tells mypy to use the provided type
annotations rather than going through typeshed. This way, the types are
always up to date when running mypy.

Remove outdated ignores since dropping Python 2.
@jdufresne
Copy link
Contributor Author

is that jwt/py.typed file supposed to be empty?

Yes, that is correct. This file is merely a marker for mypy to decide where to find type annotations. Its contents have no meaning.

For details, see:

And here is the mypy source that interacts with this file, notice it only checks that it exists and doesn't open the file:

https://github.com/python/mypy/blob/05d9fb15dcec8bde4e7184ca387e7d8acea68792/mypy/modulefinder.py#L186-L187

@jpadilla jpadilla merged commit b8cace5 into jpadilla:master Dec 16, 2020
@jdufresne jdufresne deleted the typing branch December 16, 2020 19:20
@jpadilla jpadilla added this to the v2.0.0 milestone Dec 16, 2020
DMRobertson pushed a commit to matrix-org/synapse that referenced this pull request May 2, 2022
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 this pull request may close these issues.

3 participants