-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violationshelp wantedContributions especially welcomeContributions especially welcome
Description
Summary
The fix for redundant-numeric-union (PYI041) can produce None | None, which can raise an exception.
$ cat >pyi041.py <<'# EOF'
def foo(x: None | int | None | float) -> None: ...
# EOF
$ ruff --isolated check pyi041.py --select PYI041 --fix
Found 1 error (1 fixed, 0 remaining).
$ python pyi041.py
Traceback (most recent call last):
File "pyi041.py", line 1, in <module>
def foo(x: None | None | float) -> None: ...
~~~~~^~~~~~
TypeError: unsupported operand type(s) for |: 'NoneType' and 'NoneType'One possible solution is to move the supertype to the position of the subtype if the subtype preceded it; for example, None | int | None | float would become None | float | None. None | float | None | int would still become None | float | None as it already does in Ruff 0.11.11.
Version
ruff 0.11.11 (0397682 2025-05-22)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violationshelp wantedContributions especially welcomeContributions especially welcome