[flake8-pyi] Mark PYI061 fixes unsafe in Python files#26533
Merged
Conversation
ntBre
approved these changes
Jul 7, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thank you, this makes sense to me! I just had one suggestion/request about the test location.
flake8-pyi] Mark PYI061 fixes unsafe in Python files
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI061 | 4 | 2 | 2 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+4 -4 violations, +0 -0 fixes in 3 projects; 53 projects unchanged)
apache/airflow (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL
+ airflow-core/src/airflow/serialization/definitions/dag.py:999:36: redundant-none-literal Use `Literal[...] | None` rather than `Literal[None, ...]` - airflow-core/src/airflow/serialization/definitions/dag.py:999:36: redundant-none-literal [*] Use `Literal[...] | None` rather than `Literal[None, ...]`
latchbio/latch (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ src/latch/types/metadata.py:496:45: redundant-none-literal Use `Optional[Literal[...]]` rather than `Literal[None, ...]` - src/latch/types/metadata.py:496:45: redundant-none-literal [*] Use `Optional[Literal[...]]` rather than `Literal[None, ...]`
prefecthq/prefect (+2 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ src/prefect/tasks.py:1882:19: redundant-none-literal Use `None` rather than `Literal[None]` - src/prefect/tasks.py:1882:19: redundant-none-literal [*] Use `None` rather than `Literal[None]` + src/prefect/tasks.py:1919:19: redundant-none-literal Use `None` rather than `Literal[None]` - src/prefect/tasks.py:1919:19: redundant-none-literal [*] Use `None` rather than `Literal[None]`
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| redundant-none-literal | 8 | 4 | 4 | 0 | 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #20729.
This marks
PYI061fixes as unsafe in non-stub Python files.The fix can rewrite
Literal["foo", "bar", None]intoLiteral["foo", "bar"] | None. That is equivalent for type checkers, but it is not fully equivalent at runtime: code that introspects annotations withtyping.get_args()observes a different structure after the rewrite.Stub files keep the previous behavior, since they are not runtime Python files: fixes are still safe unless comments are removed.
I also added a regression case to the existing
PYI061.pyfixture. While updating the snapshots, this also removes trailing whitespace from the affected diagnostic messages.Test Plan
Reproduced the issue before the change:
Verified that after the change, the fix is no longer applied by default and is only available with
--unsafe-fixes.Verified that the fix is still available with unsafe fixes enabled:
Ran the targeted snapshot tests:
Also ran: