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

ℹ Safe fix
2 2 | import typing
3 3 | 
4 4 | # with complex annotations
5   |-MyType = NamedTuple("MyType", [("a", int), ("b", tuple[str, ...])])
  5 |+class MyType(NamedTuple):
  6 |+    a: int
  7 |+    b: tuple[str, ...]
6 8 | 
7 9 | # with namespace
8 10 | MyType = typing.NamedTuple("MyType", [("a", int), ("b", str)])

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

ℹ Safe fix
5  5  | MyType = NamedTuple("MyType", [("a", int), ("b", tuple[str, ...])])
6  6  | 
7  7  | # with namespace
8     |-MyType = typing.NamedTuple("MyType", [("a", int), ("b", str)])
   8  |+class MyType(typing.NamedTuple):
   9  |+    a: int
   10 |+    b: str
9  11 | 
10 12 | # invalid identifiers (OK)
11 13 | MyType = NamedTuple("MyType", [("x-y", int), ("b", tuple[str, ...])])

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

ℹ Safe fix
11 11 | MyType = NamedTuple("MyType", [("x-y", int), ("b", tuple[str, ...])])
12 12 | 
13 13 | # no fields
14    |-MyType = typing.NamedTuple("MyType")
   14 |+class MyType(typing.NamedTuple):
   15 |+    pass
15 16 | 
16 17 | # empty fields
17 18 | MyType = typing.NamedTuple("MyType", [])

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

ℹ Safe fix
14 14 | MyType = typing.NamedTuple("MyType")
15 15 | 
16 16 | # empty fields
17    |-MyType = typing.NamedTuple("MyType", [])
   17 |+class MyType(typing.NamedTuple):
   18 |+    pass
18 19 | 
19 20 | # keywords
20 21 | MyType = typing.NamedTuple("MyType", a=int, b=tuple[str, ...])

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

ℹ Safe fix
17 17 | MyType = typing.NamedTuple("MyType", [])
18 18 | 
19 19 | # keywords
20    |-MyType = typing.NamedTuple("MyType", a=int, b=tuple[str, ...])
   20 |+class MyType(typing.NamedTuple):
   21 |+    a: int
   22 |+    b: tuple[str, ...]
21 23 | 
22 24 | # unfixable
23 25 | MyType = typing.NamedTuple("MyType", [("a", int)], [("b", str)])


