---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP046 [*] Generic class `A` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:11:9
   |
11 | class A(Generic[T]):
   |         ^^^^^^^^^^
12 |     # Comments in a class body are preserved
13 |     var: T
   |
help: Use type parameters
   |
10 |
   - class A(Generic[T]):
11 + class A[T: float]:
12 |     # Comments in a class body are preserved
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `B` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:16:9
   |
16 | class B(Generic[*Ts]):
   |         ^^^^^^^^^^^^
17 |     var: tuple[*Ts]
   |
help: Use type parameters
   |
15 |
   - class B(Generic[*Ts]):
16 + class B[*Ts]:
17 |     var: tuple[*Ts]
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `C` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:20:9
   |
20 | class C(Generic[P]):
   |         ^^^^^^^^^^
21 |     var: P
   |
help: Use type parameters
   |
19 |
   - class C(Generic[P]):
20 + class C[**P]:
21 |     var: P
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `Constrained` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:24:19
   |
24 | class Constrained(Generic[S]):
   |                   ^^^^^^^^^^
25 |     var: S
   |
help: Use type parameters
   |
23 |
   - class Constrained(Generic[S]):
24 + class Constrained[S: (str, bytes)]:
25 |     var: S
   |
note: This is an unsafe fix and may change runtime behavior

UP046 Generic class `ExternalType` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:30:20
   |
28 | # This case gets a diagnostic but not a fix because we can't look up the bounds
29 | # or constraints on the TypeVar imported from another module
30 | class ExternalType(Generic[T, SupportsRichComparisonT]):
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31 |     var: T
32 |     compare: SupportsRichComparisonT
   |
help: Use type parameters

UP046 [*] Generic class `MyStr` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:37:13
   |
35 | # typing.AnyStr is a common external type variable, so treat it specially as a
36 | # known TypeVar
37 | class MyStr(Generic[AnyStr]):
   |             ^^^^^^^^^^^^^^^
38 |     s: AnyStr
   |
help: Use type parameters
   |
36 | # known TypeVar
   - class MyStr(Generic[AnyStr]):
37 + class MyStr[AnyStr: (bytes, str)]:
38 |     s: AnyStr
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `MultipleGenerics` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:41:24
   |
41 | class MultipleGenerics(Generic[S, T, *Ts, P]):
   |                        ^^^^^^^^^^^^^^^^^^^^^
42 |     var: S
43 |     typ: T
   |
help: Use type parameters
   |
40 |
   - class MultipleGenerics(Generic[S, T, *Ts, P]):
41 + class MultipleGenerics[S: (str, bytes), T: float, *Ts, **P]:
42 |     var: S
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `MultipleBaseClasses` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:48:33
   |
48 | class MultipleBaseClasses(list, Generic[T]):
   |                                 ^^^^^^^^^^
49 |     var: T
   |
help: Use type parameters
   |
47 |
   - class MultipleBaseClasses(list, Generic[T]):
48 + class MultipleBaseClasses[T: float](list):
49 |     var: T
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `MoreBaseClasses` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:62:44
   |
62 | class MoreBaseClasses(Base1, Base2, Base3, Generic[T]):
   |                                            ^^^^^^^^^^
63 |     var: T
   |
help: Use type parameters
   |
61 |
   - class MoreBaseClasses(Base1, Base2, Base3, Generic[T]):
62 + class MoreBaseClasses[T: float](Base1, Base2, Base3):
63 |     var: T
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `MultipleBaseAndGenerics` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:66:52
   |
66 | class MultipleBaseAndGenerics(Base1, Base2, Base3, Generic[S, T, *Ts, P]):
   |                                                    ^^^^^^^^^^^^^^^^^^^^^
67 |     var: S
68 |     typ: T
   |
help: Use type parameters
   |
65 |
   - class MultipleBaseAndGenerics(Base1, Base2, Base3, Generic[S, T, *Ts, P]):
66 + class MultipleBaseAndGenerics[S: (str, bytes), T: float, *Ts, **P](Base1, Base2, Base3):
67 |     var: S
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `A` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:73:9
   |
73 | class A(Generic[T]): ...
   |         ^^^^^^^^^^
   |
help: Use type parameters
   |
72 |
   - class A(Generic[T]): ...
73 + class A[T: float]: ...
74 |
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `B` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:76:15
   |
76 | class B(A[S], Generic[S]):
   |               ^^^^^^^^^^
77 |     var: S
   |
help: Use type parameters
   |
75 |
   - class B(A[S], Generic[S]):
76 + class B[S: (str, bytes)](A[S]):
77 |     var: S
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `C` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:80:15
   |
80 | class C(A[S], Generic[S, T]):
   |               ^^^^^^^^^^^^^
81 |     var: tuple[S, T]
   |
help: Use type parameters
   |
79 |
   - class C(A[S], Generic[S, T]):
80 + class C[S: (str, bytes), T: float](A[S]):
81 |     var: tuple[S, T]
   |
note: This is an unsafe fix and may change runtime behavior

UP046 [*] Generic class `D` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:84:17
   |
84 | class D(A[int], Generic[T]):
   |                 ^^^^^^^^^^
85 |     var: T
   |
help: Use type parameters
   |
83 |
   - class D(A[int], Generic[T]):
84 + class D[T: float](A[int]):
85 |     var: T
   |
note: This is an unsafe fix and may change runtime behavior

UP046 Generic class `NotLast` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:88:15
   |
88 | class NotLast(Generic[T], Base1):
   |               ^^^^^^^^^^
89 |     var: T
   |
help: Use type parameters

UP046 Generic class `Sandwich` uses `Generic` subclass instead of type parameters
  --> UP046_0.py:92:23
   |
92 | class Sandwich(Base1, Generic[T], Base2):
   |                       ^^^^^^^^^^
93 |     var: T
   |
help: Use type parameters

UP046 Generic class `TooManyGenerics` uses `Generic` subclass instead of type parameters
   --> UP046_0.py:98:23
    |
 96 | # runtime `TypeError` to inherit from `Generic` multiple times, but we still
 97 | # emit a diagnostic
 98 | class TooManyGenerics(Generic[T], Generic[S]):
    |                       ^^^^^^^^^^
 99 |     var: T
100 |     var: S
    |
help: Use type parameters
