-
Notifications
You must be signed in to change notification settings - Fork 927
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
Remove type comment in favor of PEP 526 for variable annotation #2538
Conversation
Signed-off-by: Merel Theisen <[email protected]>
Signed-off-by: Merel Theisen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @merelcht! I was always a fan of type:
comments, I guess Python is solidly heading towards types as annotations...
Some questions:
- What's the role of
flake8
in typing? Does it replace MyPy, or it only checks that the annotations are correct? - May I suggest using
import typing as t
? (Silly personal preference, but I think it's nice to avoid polluting the global namespace with typing stuff, and instead I prefer to dot.Any
,t.TypedDict
and such) - May I suggest adding
from __future__ import annotations
to leverage PEP 585 and hence be able to dolist[str]
instead oft.List[str]
? (Available from Python 3.7) - Where it makes sense for this PR (without having to overhaul the whole codebase) may I suggest adding
from __future__ import annotations
to leverage PEP 604 and hence usestr | None
instead oft.Optional[str]
andstr | bytes
instead oft.Union[str, bytes]
?
I think we've always had
Is this common practice? I'm not sure I like it 😄 haha! Perhaps we can make a follow up task with several PEP update suggestions and just vote as a team?
This one I do like!
Is this one also available from Python 3.7? |
I see, thanks! Okay with keeping About PEP 604, I'm not sure, it's not clearly written in the PEP 🤔 |
I'll create a new PR to leverage PEP 585. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Description
Addresses #2078
Development notes
The problem found in #2078 was caused by the following: PyCQA/pyflakes#747 (comment) Essentially,
flake8
doesn't support type checking in comments anymore with the# type: ...
syntax. Instead it now looks for the PEP 526 syntax for variable annotation: https://peps.python.org/pep-0526/Checklist
RELEASE.md
file