---
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
---
TC006 [*] Add quotes to type expression in `typing.cast()`
 --> TC006.py:4:10
  |
2 |     from typing import cast
3 |
4 |     cast(int, 3.0)  # TC006
  |          ^^^
  |
help: Add quotes
  |
3 |
  -     cast(int, 3.0)  # TC006
4 +     cast("int", 3.0)  # TC006
5 |
  |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:10:10
   |
 8 |     from typing import cast
 9 |
10 |     cast(list[tuple[bool | float | int | str]], 3.0)  # TC006
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Add quotes
   |
9  |
   -     cast(list[tuple[bool | float | int | str]], 3.0)  # TC006
10 +     cast("list[tuple[bool | float | int | str]]", 3.0)  # TC006
11 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:16:10
   |
14 |     from typing import Union, cast
15 |
16 |     cast(list[tuple[Union[bool, float, int, str]]], 3.0)  # TC006
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Add quotes
   |
15 |
   -     cast(list[tuple[Union[bool, float, int, str]]], 3.0)  # TC006
16 +     cast("list[tuple[Union[bool, float, int, str]]]", 3.0)  # TC006
17 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:40:14
   |
38 |     from typing import cast as typecast
39 |
40 |     typecast(int, 3.0)  # TC006
   |              ^^^
   |
help: Add quotes
   |
39 |
   -     typecast(int, 3.0)  # TC006
40 +     typecast("int", 3.0)  # TC006
41 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:46:17
   |
44 |     import typing
45 |
46 |     typing.cast(int, 3.0)  # TC006
   |                 ^^^
   |
help: Add quotes
   |
45 |
   -     typing.cast(int, 3.0)  # TC006
46 +     typing.cast("int", 3.0)  # TC006
47 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:52:12
   |
50 |     import typing as t
51 |
52 |     t.cast(t.Literal["3.0", '3'], 3.0)  # TC006
   |            ^^^^^^^^^^^^^^^^^^^^^
   |
help: Add quotes
   |
51 |
   -     t.cast(t.Literal["3.0", '3'], 3.0)  # TC006
52 +     t.cast("t.Literal['3.0', '3']", 3.0)  # TC006
53 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:59:9
   |
58 |       cast(
59 | /         int  # TC006 (unsafe, because it will get rid of this comment)
60 | |         | None,
   | |______________^
61 |           3.0
62 |       )
   |
help: Add quotes
   |
58 |     cast(
   -         int  # TC006 (unsafe, because it will get rid of this comment)
   -         | None,
59 +         "int | None",
60 |         3.0
   |
note: This is an unsafe fix and may change runtime behavior

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:68:17
   |
66 |     # Regression test for #14554
67 |     import typing
68 |     typing.cast(M-())
   |                 ^^^^
   |
help: Add quotes
   |
67 |     import typing
   -     typing.cast(M-())
68 +     typing.cast("M - ()")
69 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:75:10
   |
73 |     from typing import cast, Literal
74 |
75 |     cast(Literal["A"], 'A')
   |          ^^^^^^^^^^^^
   |
help: Add quotes
   |
74 |
   -     cast(Literal["A"], 'A')
75 +     cast("Literal['A']", 'A')
76 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:82:10
   |
80 |     from typing import cast, Annotated, Literal
81 |
82 |     cast(list[Annotated["list['Literal[\"A\"]']", "Foo"]], ['A'])
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Add quotes
   |
81 |
   -     cast(list[Annotated["list['Literal[\"A\"]']", "Foo"]], ['A'])
82 +     cast("list[Annotated[list[Literal['A']], 'Foo']]", ['A'])
83 |
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:89:9
   |
88 |     cast(
89 |         int  # TC006
   |         ^^^
90 |         , 6.0
91 |     )
   |
help: Add quotes
   |
88 |     cast(
   -         int  # TC006
89 +         "int"  # TC006
90 |         , 6.0
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:98:14
   |
96 |     from typing import cast
97 |
98 |     cast(typ=int, val=3.0)  # TC006
   |              ^^^
99 |     cast(val=3.0, typ=int)  # TC006
   |
help: Add quotes
   |
97 |
   -     cast(typ=int, val=3.0)  # TC006
98 +     cast(typ="int", val=3.0)  # TC006
99 |     cast(val=3.0, typ=int)  # TC006
   |

TC006 [*] Add quotes to type expression in `typing.cast()`
  --> TC006.py:99:23
   |
98 |     cast(typ=int, val=3.0)  # TC006
99 |     cast(val=3.0, typ=int)  # TC006
   |                       ^^^
   |
help: Add quotes
   |
98 |     cast(typ=int, val=3.0)  # TC006
   -     cast(val=3.0, typ=int)  # TC006
99 +     cast(val=3.0, typ="int")  # TC006
   |
