-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
After Ruff rewrites this file, Python starts throwing an error.
t.py
from typing import Union, cast
def _make_optional(cls: type) -> type:
"""Convert a type to an Optional type."""
return cast(type, cls | None)
new_types = (int, float)
_make_optional(cast(type, Union[new_types]))output
❯ ruff --isolated --fix --target-version py311 --select UP t.py
Found 1 error (1 fixed, 0 remaining).
rewritten
from typing import Union, cast
def _make_optional(cls: type) -> type:
"""Convert a type to an Optional type."""
return cast(type, cls | None)
new_types = (int, float)
_make_optional(cast(type, new_types))Unfortunately, t.py now errors out:
Traceback (most recent call last):
File "/Users/andyfreeland/t.py", line 11, in <module>
_make_optional(cast(type, new_types))
File "/Users/andyfreeland/t.py", line 6, in _make_optional
return cast(type, cls | None)
~~~~^~~~~~
TypeError: unsupported operand type(s) for |: 'tuple' and 'NoneType'
version
ruff 0.0.252
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working