-
-
Notifications
You must be signed in to change notification settings - Fork 460
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
Introduce flake8-pyi
in pre-commit
checks
#1253
Conversation
…follow flag Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
…t case Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
…ypes with collections.abc Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
flake8-pyi
in pre-commit
checks
Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[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.
Thank you for working on setting this up.
The PR is way too big to review or merge as-is. I would prefer to split this up to activate one or a two rules at a time.
Also I hope you didn’t manually rewrite for changes like PEP 585, pyupgrade can do those automatically. That’s another tool we could add to pre-commit.
- id: flake8 | ||
additional_dependencies: | ||
- flake8-pyi | ||
types: [] | ||
files: ^.*.pyi?$ |
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.
This has stopped flake8 from running on the repo’s Python files, so we need two configurations. Also, please pin the version of flake8-pyi so there are no surprise failures when a new version is released.
- id: flake8 | |
additional_dependencies: | |
- flake8-pyi | |
types: [] | |
files: ^.*.pyi?$ | |
- id: flake8 | |
- id: flake8 | |
additional_dependencies: | |
- flake8-pyi==22.10.0 | |
types: [] | |
files: ^.*.pyi?$ |
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.
@adamchainz the glob includes .py
files (note the trailing question mark), so the flake8
hook will run on both .py
and .pyi
files. I can introduce a second hook if you want tho 😎
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.
Good point, missed that! No need for a second hook, I think, unless flake8-pyi rules will be problematic for plain python files.
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.
This looks great! I will merge this asap, so no merge-conflicts on this side will emerge.
We can later work on any further improvements.
Thank you so much, this is amazing! 🎉 👍 😊
Sorry, @adamchainz I've missed this comment :( |
I personally like to merge big style changes as-is, because otherwise it is really hard to work with merge conflicts and other PRs. This becomes a kind of a blocker to the whole process. |
@adamchainz I'm not against splitting the PR in separate ones, but even fixing a single rule per PR will end in a huge diff (esp. the PEP 604/PEP 585 stuff). Do you want me to go with enabling rules per modules in flake8 config? This is surely doable, but will take time, as there's nothing I can automate on a short sight, will have to redo the scripts first. Edit: too late, @sobolevn merged already 😎 |
- case: client_follow_flag | ||
main: | | ||
from django.test.client import Client | ||
client = Client() |
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.
What's up with these test changes? Did you base this on some other branch that isn't master
?
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! I think the pipe syntax is so much easier on the eyes than |
I notice you simplified Are we affected by this now? python/typeshed#9130
|
Yes, we are. |
Should we revert this part of the PR? Maybe hoeflint can re-run the script on an earlier commit, with this particular change disabled. And then submit a PR with the diffs. |
Yes, we should 👍 |
Yep, can revert that. IIRC there were only |
…41 rule Signed-off-by: Oleg Hoefling <[email protected]>
) Signed-off-by: Oleg Hoefling <[email protected]> Signed-off-by: Oleg Hoefling <[email protected]>
This is a PR similar to typeddjango/django-stubs#1253, only for rest_framework-stubs. All statements that are unclear on how to proceed are marked with # noqa: in the code, with the exception of compat.pyi, which has additional rules turned off in setup.cfg. * configure flake8-pyi plugin in pre-commit * fix Y015 * fix Y037 * use PEP 585 container types where possible, replace obsolete typing types with collections.abc * disable Y041 rule * add typealias annotation where feasible, add self annotations * fix failing tests, silence remaining warnings since unclear how to proceed * address review * amend tests * amend rebase error Signed-off-by: Oleg Hoefling <[email protected]>
fget: Callable[[Self], _Get] | None | ||
def __init__(self: Self, method: Callable[[Self], _Get] | None = ...) -> None: ... | ||
def __get__(self: Self, instance: Self | None, cls: type[Self] = ...) -> _Get: ... | ||
def getter(self: Self, method: Callable[[Self], _Get]) -> classproperty[_Get]: ... |
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.
typeddjango#1253 switched this project to use the union type syntax ( https://peps.python.org/pep-0604/ ), which is only available in Python >=3.10. Earlier versions of Python have no support for this syntax.
I have made things!
This PR adds
pre-commit
check usingflake8-pyi
. Most of the warnings are fixed alongside, warnings that conflict with the currentmypy
state (e.g. python/mypy#11098, python/mypy#12393 or python/mypy#13437) are disabled with an explicit comment linking to the relatedmypy
issue.Warnings that were disabled globally:
Y021
- looks like docstrings are used here and there, esp. the one forField
stub is usefulY024
- switching fromnamedtuple
toNamedTuple
can be done in an automated fashion, but fields will be typed withAny
. Not sure if this will be of any helpY043
- IMO renaming the aliases is more harm than goodRelated issues
Closes #128