Skip to content

Use PEP 604 style annotations #150

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
twoertwein opened this issue Jul 18, 2022 · 4 comments · Fixed by #151
Closed

Use PEP 604 style annotations #150

twoertwein opened this issue Jul 18, 2022 · 4 comments · Fixed by #151

Comments

@twoertwein
Copy link
Member

We might consider using the new(er) type annotation system (replace Union with |, use list and so on):

Y037 (enforcing PEP 604 syntax everywhere) is not yet fully compatible with the mypy type checker, which has a few bugs regarding PEP 604 type aliases.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 18, 2022

My only concern here is compatibility with python 3.8 and 3.9. Maybe we just have to do from future import __annotations__ throughout.

@twoertwein
Copy link
Member Author

As a first step we could only change pyi files (not the tests). pyi files do not need from future import __annotations__. flake8-pyi:

Y044: from __future__ import annotations has no effect in stub files, as forward references in stubs are enabled by default.

Adding the future imports to the tests would be fairly easy as there are only a few (but large) test files.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 18, 2022

You're certainly welcome to try to make the changes in a PR!

@twoertwein
Copy link
Member Author

You're certainly welcome to try to make the changes in a PR!

I think a feasible approach would be to first use pre-commit (currently we do not let it re-write annotations) and then manually re-write annotations when flake8-pyi recommends changes (should probably ignore Y037 for now).

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.

2 participants