Skip to content

STYL: replace autotyping with ruff's ANN autofixes #54260

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

Merged
merged 4 commits into from
Jul 28, 2023
Merged

STYL: replace autotyping with ruff's ANN autofixes #54260

merged 4 commits into from
Jul 28, 2023

Conversation

twoertwein
Copy link
Member

@twoertwein twoertwein commented Jul 25, 2023

ruff's ANN has many of the autofixes from autotyping but it doesn't have all of them. Ruff doesn't annotate parameters with simple default values (autotyping would change def foo(x=1) to def foo(x: int = 1)).

@twoertwein twoertwein marked this pull request as ready for review July 26, 2023 15:43
@@ -25,6 +25,9 @@ repos:
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
- id: ruff
name: ruff's autotyping/flake8-annotations autofixes
args: [--select, ANN, --fix-only, --exit-non-zero-on-fix]
Copy link
Member

Choose a reason for hiding this comment

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

Could we just include ANN as a rule in pyproject.toml?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wish, but there are way too many violations (ANN wants everything to be annotated) and only some of them have in some cases an autofix. I would like only to use the autofixes. If there is a better way to achieve that, I'm all for that - but I didn't find one.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm since it appears ANN204 is the only auto-fix rule so far, could we just include that code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me put this back to draft and wait until #54271 is merged

Copy link
Member Author

Choose a reason for hiding this comment

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

There are 191 methods without return annotations.

Copy link
Member Author

Choose a reason for hiding this comment

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

I currently do not have time to add 191 return annotations but I will start working on it in the future.

ruff might have autofixes for ANN001 in the future astral-sh/ruff#1640

@mroeschke mroeschke added Code Style Code style, linting, code_checks Typing type annotations, mypy/pyright type checking labels Jul 26, 2023
@twoertwein twoertwein marked this pull request as draft July 26, 2023 22:33
@twoertwein twoertwein marked this pull request as ready for review July 28, 2023 13:52
@twoertwein twoertwein requested a review from MarcoGorelli July 28, 2023 14:11
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

small comment, but rest looks good

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

nice one, never liked having scripts/run_autotyping

@mroeschke mroeschke added this to the 2.1 milestone Jul 28, 2023
@mroeschke mroeschke merged commit a32a328 into pandas-dev:main Jul 28, 2023
@mroeschke
Copy link
Member

Thanks @twoertwein

@twoertwein twoertwein deleted the ruff branch August 9, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants