---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax
 --> UP014.py:5:1
  |
4 | # with complex annotations
5 | MyType = NamedTuple("MyType", [("a", int), ("b", tuple[str, ...])])
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
7 | # with namespace
  |
help: Convert `MyType` to class syntax
  |
4 | # with complex annotations
  - MyType = NamedTuple("MyType", [("a", int), ("b", tuple[str, ...])])
5 + class MyType(NamedTuple):
6 +     a: int
7 +     b: tuple[str, ...]
8 |
  |

UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax
  --> UP014.py:8:1
   |
 7 | # with namespace
 8 | MyType = typing.NamedTuple("MyType", [("a", int), ("b", str)])
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 9 |
10 | # invalid identifiers (OK)
   |
help: Convert `MyType` to class syntax
   |
7  | # with namespace
   - MyType = typing.NamedTuple("MyType", [("a", int), ("b", str)])
8  + class MyType(typing.NamedTuple):
9  +     a: int
10 +     b: str
11 |
   |

UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax
  --> UP014.py:14:1
   |
13 | # no fields
14 | MyType = typing.NamedTuple("MyType")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 |
16 | # empty fields
   |
help: Convert `MyType` to class syntax
   |
13 | # no fields
   - MyType = typing.NamedTuple("MyType")
14 + class MyType(typing.NamedTuple):
15 +     pass
16 |
   |

UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax
  --> UP014.py:17:1
   |
16 | # empty fields
17 | MyType = typing.NamedTuple("MyType", [])
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18 |
19 | # keywords
   |
help: Convert `MyType` to class syntax
   |
16 | # empty fields
   - MyType = typing.NamedTuple("MyType", [])
17 + class MyType(typing.NamedTuple):
18 +     pass
19 |
   |

UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax
  --> UP014.py:20:1
   |
19 | # keywords
20 | MyType = typing.NamedTuple("MyType", a=int, b=tuple[str, ...])
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21 |
22 | # unfixable
   |
help: Convert `MyType` to class syntax
   |
19 | # keywords
   - MyType = typing.NamedTuple("MyType", a=int, b=tuple[str, ...])
20 + class MyType(typing.NamedTuple):
21 +     a: int
22 +     b: tuple[str, ...]
23 |
   |

UP014 [*] Convert `X` from `NamedTuple` functional to class syntax
  --> UP014.py:36:1
   |
35 |   # Unsafe fix if comments are present
36 | / X = NamedTuple("X", [
37 | |     ("some_config", int),  # important
38 | | ])
   | |__^
   |
help: Convert `X` to class syntax
   |
35 | # Unsafe fix if comments are present
   - X = NamedTuple("X", [
   -     ("some_config", int),  # important
   - ])
36 + class X(NamedTuple):
37 +     some_config: int
38 |
   |
note: This is an unsafe fix and may change runtime behavior
