---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP013.py:5:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
  |
4 | # dict literal
5 | MyType = TypedDict("MyType", {"a": int, "b": str})
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
6 | 
7 | # dict call
  |
  = help: Convert `MyType` to class syntax

ℹ Safe fix
2 2 | import typing
3 3 | 
4 4 | # dict literal
5   |-MyType = TypedDict("MyType", {"a": int, "b": str})
  5 |+class MyType(TypedDict):
  6 |+    a: int
  7 |+    b: str
6 8 | 
7 9 | # dict call
8 10 | MyType = TypedDict("MyType", dict(a=int, b=str))

UP013.py:8:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
 7 | # dict call
 8 | MyType = TypedDict("MyType", dict(a=int, b=str))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
 9 | 
10 | # kwargs
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
5  5  | MyType = TypedDict("MyType", {"a": int, "b": str})
6  6  | 
7  7  | # dict call
8     |-MyType = TypedDict("MyType", dict(a=int, b=str))
   8  |+class MyType(TypedDict):
   9  |+    a: int
   10 |+    b: str
9  11 | 
10 12 | # kwargs
11 13 | MyType = TypedDict("MyType", a=int, b=str)

UP013.py:11:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
10 | # kwargs
11 | MyType = TypedDict("MyType", a=int, b=str)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
12 | 
13 | # Empty TypedDict
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
8  8  | MyType = TypedDict("MyType", dict(a=int, b=str))
9  9  | 
10 10 | # kwargs
11    |-MyType = TypedDict("MyType", a=int, b=str)
   11 |+class MyType(TypedDict):
   12 |+    a: int
   13 |+    b: str
12 14 | 
13 15 | # Empty TypedDict
14 16 | MyType = TypedDict("MyType")

UP013.py:14:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
13 | # Empty TypedDict
14 | MyType = TypedDict("MyType")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
15 | 
16 | # Literal values
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
11 11 | MyType = TypedDict("MyType", a=int, b=str)
12 12 | 
13 13 | # Empty TypedDict
14    |-MyType = TypedDict("MyType")
   14 |+class MyType(TypedDict):
   15 |+    pass
15 16 | 
16 17 | # Literal values
17 18 | MyType = TypedDict("MyType", {"a": "hello"})

UP013.py:17:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
16 | # Literal values
17 | MyType = TypedDict("MyType", {"a": "hello"})
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
18 | MyType = TypedDict("MyType", a="hello")
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
14 14 | MyType = TypedDict("MyType")
15 15 | 
16 16 | # Literal values
17    |-MyType = TypedDict("MyType", {"a": "hello"})
   17 |+class MyType(TypedDict):
   18 |+    a: "hello"
18 19 | MyType = TypedDict("MyType", a="hello")
19 20 | 
20 21 | # NotRequired

UP013.py:18:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
16 | # Literal values
17 | MyType = TypedDict("MyType", {"a": "hello"})
18 | MyType = TypedDict("MyType", a="hello")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
19 | 
20 | # NotRequired
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
15 15 | 
16 16 | # Literal values
17 17 | MyType = TypedDict("MyType", {"a": "hello"})
18    |-MyType = TypedDict("MyType", a="hello")
   18 |+class MyType(TypedDict):
   19 |+    a: "hello"
19 20 | 
20 21 | # NotRequired
21 22 | MyType = TypedDict("MyType", {"a": NotRequired[dict]})

UP013.py:21:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
20 | # NotRequired
21 | MyType = TypedDict("MyType", {"a": NotRequired[dict]})
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
22 | 
23 | # total
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
18 18 | MyType = TypedDict("MyType", a="hello")
19 19 | 
20 20 | # NotRequired
21    |-MyType = TypedDict("MyType", {"a": NotRequired[dict]})
   21 |+class MyType(TypedDict):
   22 |+    a: NotRequired[dict]
22 23 | 
23 24 | # total
24 25 | MyType = TypedDict("MyType", {"x": int, "y": int}, total=False)

UP013.py:24:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
23 | # total
24 | MyType = TypedDict("MyType", {"x": int, "y": int}, total=False)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
25 | 
26 | # using Literal type
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
21 21 | MyType = TypedDict("MyType", {"a": NotRequired[dict]})
22 22 | 
23 23 | # total
24    |-MyType = TypedDict("MyType", {"x": int, "y": int}, total=False)
   24 |+class MyType(TypedDict, total=False):
   25 |+    x: int
   26 |+    y: int
25 27 | 
26 28 | # using Literal type
27 29 | MyType = TypedDict("MyType", {"key": Literal["value"]})

UP013.py:27:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
26 | # using Literal type
27 | MyType = TypedDict("MyType", {"key": Literal["value"]})
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
28 | 
29 | # using namespace TypedDict
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
24 24 | MyType = TypedDict("MyType", {"x": int, "y": int}, total=False)
25 25 | 
26 26 | # using Literal type
27    |-MyType = TypedDict("MyType", {"key": Literal["value"]})
   27 |+class MyType(TypedDict):
   28 |+    key: Literal["value"]
28 29 | 
29 30 | # using namespace TypedDict
30 31 | MyType = typing.TypedDict("MyType", {"key": int})

UP013.py:30:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
29 | # using namespace TypedDict
30 | MyType = typing.TypedDict("MyType", {"key": int})
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
31 | 
32 | # invalid identifiers (OK)
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
27 27 | MyType = TypedDict("MyType", {"key": Literal["value"]})
28 28 | 
29 29 | # using namespace TypedDict
30    |-MyType = typing.TypedDict("MyType", {"key": int})
   30 |+class MyType(typing.TypedDict):
   31 |+    key: int
31 32 | 
32 33 | # invalid identifiers (OK)
33 34 | MyType = TypedDict("MyType", {"in": int, "x-y": int})

UP013.py:40:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
39 | # Empty dict literal
40 | MyType = TypedDict("MyType", {})
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
41 | 
42 | # Empty dict call
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
37 37 | MyType = TypedDict("MyType", {"a": int, "b": str, **c})
38 38 | 
39 39 | # Empty dict literal
40    |-MyType = TypedDict("MyType", {})
   40 |+class MyType(TypedDict):
   41 |+    pass
41 42 | 
42 43 | # Empty dict call
43 44 | MyType = TypedDict("MyType", dict())

UP013.py:43:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax
   |
42 | # Empty dict call
43 | MyType = TypedDict("MyType", dict())
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013
   |
   = help: Convert `MyType` to class syntax

ℹ Safe fix
40 40 | MyType = TypedDict("MyType", {})
41 41 | 
42 42 | # Empty dict call
43    |-MyType = TypedDict("MyType", dict())
   43 |+class MyType(TypedDict):
   44 |+    pass


