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

[flake8-pyi]: More autofixes for redundant-none-literal (PYI061) #14872

Merged
merged 8 commits into from
Dec 12, 2024

Conversation

kiran-4444
Copy link
Contributor

Summary

This PR solves #14537. I've tested it, and it's working as expected. I'll be updating this with tests tomorrow. The implementation isn't yet sanitised and can be refactored further. Any feedback in doing this is greatly appreciated.

Test Plan

Tested locally, will update the tests.

@kiran-4444 kiran-4444 changed the title [flake8-pyi]: More autofixes for redundant-none-literal/PYI061 (PYI061) [flake8-pyi]: More autofixes for redundant-none-literal (PYI061) Dec 9, 2024
@AlexWaygood AlexWaygood added the fixes Related to suggested fixes for violations label Dec 9, 2024
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! A couple of issues here, but this broadly looks like it's on the right track :-)

Copy link
Contributor

github-actions bot commented Dec 11, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -1 violations, +16 -0 fixes in 2 projects; 53 projects unchanged)

pandas-dev/pandas (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- pandas/core/groupby/groupby.py:4082:39: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`

zulip/zulip (+0 -0 violations, +16 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ corporate/views/billing_page.py:326:24: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/billing_page.py:326:24: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
+ corporate/views/remote_billing_page.py:158:26: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/remote_billing_page.py:158:26: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
+ corporate/views/remote_billing_page.py:159:42: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/remote_billing_page.py:159:42: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
+ corporate/views/remote_billing_page.py:160:48: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/remote_billing_page.py:160:48: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
+ corporate/views/remote_billing_page.py:678:26: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/remote_billing_page.py:678:26: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
+ corporate/views/remote_billing_page.py:679:42: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/remote_billing_page.py:679:42: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
+ corporate/views/remote_billing_page.py:680:48: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/remote_billing_page.py:680:48: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
+ corporate/views/remote_billing_page.py:70:5: PYI061 [*] `Literal[None, ...]` can be replaced with `Literal[...] | None`
- corporate/views/remote_billing_page.py:70:5: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PYI061 17 0 1 16 0

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks @kiran-4444, this is a fantastic improvement! I pushed a couple of small changes:

  • We can't safely offer the fix with the | syntax on Python <=3.9, as the | syntax for unions was added in Python 3.10. Possibly we could in the future use typing.Union for the fix and offer it even on older versions of Python, but I think we can leave that to another PR :-)
  • I simplified the code slightly by combining the two create_fix_edit() functions

@AlexWaygood AlexWaygood enabled auto-merge (squash) December 12, 2024 19:43
@AlexWaygood AlexWaygood merged commit e5cb4d6 into astral-sh:main Dec 12, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants