---
source: crates/ruff/src/rules/pyupgrade/mod.rs
---
UP007.py:6:10: UP007 [*] Use `X | Y` for type annotations
  |
6 | def f(x: Optional[str]) -> None:
  |          ^^^^^^^^^^^^^ UP007
7 |     ...
  |
  = help: Convert to `X | Y`

ℹ Suggested fix
3 3 | from typing import Union
4 4 | 
5 5 | 
6   |-def f(x: Optional[str]) -> None:
  6 |+def f(x: str | None) -> None:
7 7 |     ...
8 8 | 
9 9 | 

UP007.py:10:10: UP007 [*] Use `X | Y` for type annotations
   |
10 | def f(x: typing.Optional[str]) -> None:
   |          ^^^^^^^^^^^^^^^^^^^^ UP007
11 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
7  7  |     ...
8  8  | 
9  9  | 
10    |-def f(x: typing.Optional[str]) -> None:
   10 |+def f(x: str | None) -> None:
11 11 |     ...
12 12 | 
13 13 | 

UP007.py:14:10: UP007 [*] Use `X | Y` for type annotations
   |
14 | def f(x: Union[str, int, Union[float, bytes]]) -> None:
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007
15 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
11 11 |     ...
12 12 | 
13 13 | 
14    |-def f(x: Union[str, int, Union[float, bytes]]) -> None:
   14 |+def f(x: str | int | Union[float, bytes]) -> None:
15 15 |     ...
16 16 | 
17 17 | 

UP007.py:14:26: UP007 [*] Use `X | Y` for type annotations
   |
14 | def f(x: Union[str, int, Union[float, bytes]]) -> None:
   |                          ^^^^^^^^^^^^^^^^^^^ UP007
15 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
11 11 |     ...
12 12 | 
13 13 | 
14    |-def f(x: Union[str, int, Union[float, bytes]]) -> None:
   14 |+def f(x: Union[str, int, float | bytes]) -> None:
15 15 |     ...
16 16 | 
17 17 | 

UP007.py:18:10: UP007 [*] Use `X | Y` for type annotations
   |
18 | def f(x: typing.Union[str, int]) -> None:
   |          ^^^^^^^^^^^^^^^^^^^^^^ UP007
19 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
15 15 |     ...
16 16 | 
17 17 | 
18    |-def f(x: typing.Union[str, int]) -> None:
   18 |+def f(x: str | int) -> None:
19 19 |     ...
20 20 | 
21 21 | 

UP007.py:22:10: UP007 [*] Use `X | Y` for type annotations
   |
22 | def f(x: typing.Union[(str, int)]) -> None:
   |          ^^^^^^^^^^^^^^^^^^^^^^^^ UP007
23 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
19 19 |     ...
20 20 | 
21 21 | 
22    |-def f(x: typing.Union[(str, int)]) -> None:
   22 |+def f(x: str | int) -> None:
23 23 |     ...
24 24 | 
25 25 | 

UP007.py:26:10: UP007 [*] Use `X | Y` for type annotations
   |
26 | def f(x: typing.Union[(str, int), float]) -> None:
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007
27 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
23 23 |     ...
24 24 | 
25 25 | 
26    |-def f(x: typing.Union[(str, int), float]) -> None:
   26 |+def f(x: (str, int) | float) -> None:
27 27 |     ...
28 28 | 
29 29 | 

UP007.py:30:11: UP007 [*] Use `X | Y` for type annotations
   |
30 | def f(x: "Union[str, int, Union[float, bytes]]") -> None:
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007
31 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
27 27 |     ...
28 28 | 
29 29 | 
30    |-def f(x: "Union[str, int, Union[float, bytes]]") -> None:
   30 |+def f(x: "str | int | Union[float, bytes]") -> None:
31 31 |     ...
32 32 | 
33 33 | 

UP007.py:30:27: UP007 [*] Use `X | Y` for type annotations
   |
30 | def f(x: "Union[str, int, Union[float, bytes]]") -> None:
   |                           ^^^^^^^^^^^^^^^^^^^ UP007
31 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
27 27 |     ...
28 28 | 
29 29 | 
30    |-def f(x: "Union[str, int, Union[float, bytes]]") -> None:
   30 |+def f(x: "Union[str, int, float | bytes]") -> None:
31 31 |     ...
32 32 | 
33 33 | 

UP007.py:34:11: UP007 [*] Use `X | Y` for type annotations
   |
34 | def f(x: "typing.Union[str, int]") -> None:
   |           ^^^^^^^^^^^^^^^^^^^^^^ UP007
35 |     ...
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
31 31 |     ...
32 32 | 
33 33 | 
34    |-def f(x: "typing.Union[str, int]") -> None:
   34 |+def f(x: "str | int") -> None:
35 35 |     ...
36 36 | 
37 37 | 

UP007.py:47:8: UP007 [*] Use `X | Y` for type annotations
   |
47 | def f() -> None:
48 |     x: Optional[str]
   |        ^^^^^^^^^^^^^ UP007
49 |     x = Optional[str]
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
44 44 | 
45 45 | 
46 46 | def f() -> None:
47    |-    x: Optional[str]
   47 |+    x: str | None
48 48 |     x = Optional[str]
49 49 | 
50 50 |     x = Union[str, int]

UP007.py:52:8: UP007 [*] Use `X | Y` for type annotations
   |
52 |     x = Union[str, int]
53 |     x = Union["str", "int"]
54 |     x: Union[str, int]
   |        ^^^^^^^^^^^^^^^ UP007
55 |     x: Union["str", "int"]
   |
   = help: Convert to `X | Y`

ℹ Suggested fix
49 49 | 
50 50 |     x = Union[str, int]
51 51 |     x = Union["str", "int"]
52    |-    x: Union[str, int]
   52 |+    x: str | int
53 53 |     x: Union["str", "int"]


