---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP047 [*] Generic function `f` should use type parameters
  --> UP047_0.py:12:5
   |
12 | def f(t: T) -> T:
   |     ^^^^^^^
13 |     return t
   |
help: Use type parameters
   |
11 |
   - def f(t: T) -> T:
12 + def f[T: float](t: T) -> T:
13 |     return t
   |
note: This is an unsafe fix and may change runtime behavior

UP047 [*] Generic function `g` should use type parameters
  --> UP047_0.py:16:5
   |
16 | def g(ts: tuple[*Ts]) -> tuple[*Ts]:
   |     ^^^^^^^^^^^^^^^^^
17 |     return ts
   |
help: Use type parameters
   |
15 |
   - def g(ts: tuple[*Ts]) -> tuple[*Ts]:
16 + def g[*Ts](ts: tuple[*Ts]) -> tuple[*Ts]:
17 |     return ts
   |
note: This is an unsafe fix and may change runtime behavior

UP047 [*] Generic function `h` should use type parameters
  --> UP047_0.py:20:5
   |
20 |   def h(
   |  _____^
21 | |     p: Callable[P, T],
22 | |     # Comment in the middle of a parameter list should be preserved
23 | |     another_param,
24 | |     and_another,
25 | | ) -> Callable[P, T]:
   | |_^
26 |       return p
   |
help: Use type parameters
   |
19 |
   - def h(
20 + def h[**P, T: float](
21 |     p: Callable[P, T],
   |
note: This is an unsafe fix and may change runtime behavior

UP047 [*] Generic function `i` should use type parameters
  --> UP047_0.py:29:5
   |
29 | def i(s: S) -> S:
   |     ^^^^^^^
30 |     return s
   |
help: Use type parameters
   |
28 |
   - def i(s: S) -> S:
29 + def i[S: (str, bytes)](s: S) -> S:
30 |     return s
   |
note: This is an unsafe fix and may change runtime behavior

UP047 [*] Generic function `broken_fix` should use type parameters
  --> UP047_0.py:39:5
   |
37 | # TypeVars with the new-style generic syntax and will be rejected by type
38 | # checkers
39 | def broken_fix(okay: T, bad: Something) -> tuple[T, Something]:
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40 |     return (okay, bad)
   |
help: Use type parameters
   |
38 | # checkers
   - def broken_fix(okay: T, bad: Something) -> tuple[T, Something]:
39 + def broken_fix[T: float](okay: T, bad: Something) -> tuple[T, Something]:
40 |     return (okay, bad)
   |
note: This is an unsafe fix and may change runtime behavior

UP047 [*] Generic function `any_str_param` should use type parameters
  --> UP047_0.py:43:5
   |
43 | def any_str_param(s: AnyStr) -> AnyStr:
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
44 |     return s
   |
help: Use type parameters
   |
42 |
   - def any_str_param(s: AnyStr) -> AnyStr:
43 + def any_str_param[AnyStr: (bytes, str)](s: AnyStr) -> AnyStr:
44 |     return s
   |
note: This is an unsafe fix and may change runtime behavior

UP047 [*] Generic function `multi_param` should use type parameters
  --> UP047_0.py:56:5
   |
55 | # TypeVar used in multiple parameter annotations should still be detected
56 | def multi_param(t: list[T], c: Callable[[T], None]) -> T:
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57 |     c(t[0])
58 |     return t[1]
   |
help: Use type parameters
   |
55 | # TypeVar used in multiple parameter annotations should still be detected
   - def multi_param(t: list[T], c: Callable[[T], None]) -> T:
56 + def multi_param[T: float](t: list[T], c: Callable[[T], None]) -> T:
57 |     c(t[0])
   |
note: This is an unsafe fix and may change runtime behavior
