Skip to content

[flake8-pyi]: Stabilize: Provide more automated fixes for duplicate-union-members (PYI016)#15342

Merged
MichaReiser merged 2 commits intoruff-0.9from
micha/pyi016-fix
Jan 8, 2025
Merged

[flake8-pyi]: Stabilize: Provide more automated fixes for duplicate-union-members (PYI016)#15342
MichaReiser merged 2 commits intoruff-0.9from
micha/pyi016-fix

Conversation

@MichaReiser
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser commented Jan 8, 2025

Summary

Stabilizes the fix extension introduced in #14270

Test Plan

There are no open issues related to PYI016 fixes. The most recent issue was fixed on Nov 25. There are also no open issues with the rule itself.

I reviewed the ecosystem changes and they look good.

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule fixes Related to suggested fixes for violations and removed rule Implementing or modifying a lint rule labels Jan 8, 2025
@MichaReiser MichaReiser changed the title [flake8-pyi]: Stabilize: Provide more automated fixes for duplicate-union-members (PYI016) [flake8-pyi]: Stabilize: Provide more automated fixes for duplicate-union-members (PYI016) Jan 8, 2025
// Generate a [`Fix`] for a single type expression, e.g. `int`.
Some(Fix::applicable_edit(
Edit::range_replacement(checker.generator().expr(edit_expr), expr.range()),
// Mark [`Fix`] as unsafe when comments are in range.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It seems like #14270 incorrectly removed the fix for non-preview 🤷 So, technically, this PR makes the rule fixable again

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hehe, onwards and upwards!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 8, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+0 -0 violations, +10 -0 fixes in 3 projects; 52 projects unchanged)

apache/airflow (+0 -0 violations, +2 -0 fixes)

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

- providers/src/airflow/providers/microsoft/azure/operators/container_instances.py:254:43: PYI016 Duplicate union member `VolumeMount`
+ providers/src/airflow/providers/microsoft/azure/operators/container_instances.py:254:43: PYI016 [*] Duplicate union member `VolumeMount`

apache/superset (+0 -0 violations, +2 -0 fixes)

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

- superset/models/helpers.py:905:39: PYI016 Duplicate union member `str`
+ superset/models/helpers.py:905:39: PYI016 [*] Duplicate union member `str`

bokeh/bokeh (+0 -0 violations, +6 -0 fixes)

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

- src/bokeh/core/property/factors.py:51:56: PYI016 Duplicate union member `tuple[str, str]`
+ src/bokeh/core/property/factors.py:51:56: PYI016 [*] Duplicate union member `tuple[str, str]`
- src/bokeh/core/property/factors.py:52:85: PYI016 Duplicate union member `tp.Sequence[tuple[str, str]]`
+ src/bokeh/core/property/factors.py:52:85: PYI016 [*] Duplicate union member `tp.Sequence[tuple[str, str]]`
- src/bokeh/plotting/contour.py:43:88: PYI016 Duplicate union member `ContourColor`
+ src/bokeh/plotting/contour.py:43:88: PYI016 [*] Duplicate union member `ContourColor`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PYI016 10 0 0 10 0

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser added this to the v0.9 milestone Jan 8, 2025
field34: typing.Union[list[int], str] | typing.Union[bytes, list[int]] # Error


field35: "int | str" | int # Error, but currently not detected
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood Jan 8, 2025

Choose a reason for hiding this comment

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

I'm not sure I'd want to extend the rule to detect this, since:

  • It seems like an unlikely edge case
  • It will fail at runtime with TypeError unless you have from __future__ import annotations at the top of the file (and if you do, there's no need to quote any annotations anyway)
  • In a stub file it won't fail, but you shouldn't ever use quoted annotations in a stub file anyway, and we have PYI020 to tell you off about that if you do

So I don't think it would be worth the added complexity

Copy link
Copy Markdown
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.

All LGTM other than https://github.com/astral-sh/ruff/pull/15342/files#r1906988995.

Thanks so much @sbrugman for this improvement. Changes like this make me really happy. It's still so cool that Ruff can provide sophisticated autofixes like this 😃

@MichaReiser MichaReiser merged commit 207ed56 into ruff-0.9 Jan 8, 2025
@MichaReiser MichaReiser deleted the micha/pyi016-fix branch January 8, 2025 12:13
@MichaReiser MichaReiser mentioned this pull request Jan 8, 2025
2 tasks
MichaReiser added a commit that referenced this pull request Jan 8, 2025
MichaReiser added a commit that referenced this pull request Jan 9, 2025
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