---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF041 [*] Unnecessary nested `Literal`
 --> RUF041.pyi:6:4
  |
6 | y: Literal[1, print("hello"), 3, Literal[4, 1]]
  |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 | Literal[1, Literal[1]]
8 | Literal[1, 2, Literal[1, 2]]
  |
help: Replace with flattened `Literal`
  |
5 |
  - y: Literal[1, print("hello"), 3, Literal[4, 1]]
6 + y: Literal[1, print("hello"), 3, 4, 1]
7 | Literal[1, Literal[1]]
  |

RUF041 [*] Unnecessary nested `Literal`
 --> RUF041.pyi:7:1
  |
6 | y: Literal[1, print("hello"), 3, Literal[4, 1]]
7 | Literal[1, Literal[1]]
  | ^^^^^^^^^^^^^^^^^^^^^^
8 | Literal[1, 2, Literal[1, 2]]
9 | Literal[1, Literal[1], Literal[1]]
  |
help: Replace with flattened `Literal`
  |
6 | y: Literal[1, print("hello"), 3, Literal[4, 1]]
  - Literal[1, Literal[1]]
7 + Literal[1, 1]
8 | Literal[1, 2, Literal[1, 2]]
  |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:8:1
   |
 6 | y: Literal[1, print("hello"), 3, Literal[4, 1]]
 7 | Literal[1, Literal[1]]
 8 | Literal[1, 2, Literal[1, 2]]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 9 | Literal[1, Literal[1], Literal[1]]
10 | Literal[1, Literal[2], Literal[2]]
   |
help: Replace with flattened `Literal`
  |
7 | Literal[1, Literal[1]]
  - Literal[1, 2, Literal[1, 2]]
8 + Literal[1, 2, 1, 2]
9 | Literal[1, Literal[1], Literal[1]]
  |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:9:1
   |
 7 | Literal[1, Literal[1]]
 8 | Literal[1, 2, Literal[1, 2]]
 9 | Literal[1, Literal[1], Literal[1]]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10 | Literal[1, Literal[2], Literal[2]]
11 | t.Literal[1, t.Literal[2, t.Literal[1]]]
   |
help: Replace with flattened `Literal`
   |
8  | Literal[1, 2, Literal[1, 2]]
   - Literal[1, Literal[1], Literal[1]]
9  + Literal[1, 1, 1]
10 | Literal[1, Literal[2], Literal[2]]
   |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:10:1
   |
 8 | Literal[1, 2, Literal[1, 2]]
 9 | Literal[1, Literal[1], Literal[1]]
10 | Literal[1, Literal[2], Literal[2]]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 | t.Literal[1, t.Literal[2, t.Literal[1]]]
12 | Literal[
   |
help: Replace with flattened `Literal`
   |
9  | Literal[1, Literal[1], Literal[1]]
   - Literal[1, Literal[2], Literal[2]]
10 + Literal[1, 2, 2]
11 | t.Literal[1, t.Literal[2, t.Literal[1]]]
   |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:11:1
   |
 9 | Literal[1, Literal[1], Literal[1]]
10 | Literal[1, Literal[2], Literal[2]]
11 | t.Literal[1, t.Literal[2, t.Literal[1]]]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 | Literal[
13 |     1, # comment 1
   |
help: Replace with flattened `Literal`
   |
10 | Literal[1, Literal[2], Literal[2]]
   - t.Literal[1, t.Literal[2, t.Literal[1]]]
11 + t.Literal[1, 2, 1]
12 | Literal[
   |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:12:1
   |
10 |   Literal[1, Literal[2], Literal[2]]
11 |   t.Literal[1, t.Literal[2, t.Literal[1]]]
12 | / Literal[
13 | |     1, # comment 1
14 | |     Literal[ # another comment
15 | |         1 # yet another comment
16 | |     ]
17 | | ]  # once
   | |_^
18 |
19 |   # Ensure issue is only raised once, even on nested literals
   |
help: Replace with flattened `Literal`
   |
11 | t.Literal[1, t.Literal[2, t.Literal[1]]]
   - Literal[
   -     1, # comment 1
   -     Literal[ # another comment
   -         1 # yet another comment
   -     ]
   - ]  # once
12 + Literal[1, 1]  # once
13 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:20:10
   |
19 | # Ensure issue is only raised once, even on nested literals
20 | MyType = Literal["foo", Literal[True, False, True], "bar"]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21 |
22 | # nested literals, all equivalent to `Literal[1]`
   |
help: Replace with flattened `Literal`
   |
19 | # Ensure issue is only raised once, even on nested literals
   - MyType = Literal["foo", Literal[True, False, True], "bar"]
20 + MyType = Literal["foo", True, False, True, "bar"]
21 |
   |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:23:1
   |
22 | # nested literals, all equivalent to `Literal[1]`
23 | Literal[Literal[1]]
   | ^^^^^^^^^^^^^^^^^^^
24 | Literal[Literal[Literal[1], Literal[1]]]
25 | Literal[Literal[1], Literal[Literal[Literal[1]]]]
   |
help: Replace with flattened `Literal`
   |
22 | # nested literals, all equivalent to `Literal[1]`
   - Literal[Literal[1]]
23 + Literal[1]
24 | Literal[Literal[Literal[1], Literal[1]]]
   |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:24:1
   |
22 | # nested literals, all equivalent to `Literal[1]`
23 | Literal[Literal[1]]
24 | Literal[Literal[Literal[1], Literal[1]]]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25 | Literal[Literal[1], Literal[Literal[Literal[1]]]]
   |
help: Replace with flattened `Literal`
   |
23 | Literal[Literal[1]]
   - Literal[Literal[Literal[1], Literal[1]]]
24 + Literal[1, 1]
25 | Literal[Literal[1], Literal[Literal[Literal[1]]]]
   |

RUF041 [*] Unnecessary nested `Literal`
  --> RUF041.pyi:25:1
   |
23 | Literal[Literal[1]]
24 | Literal[Literal[Literal[1], Literal[1]]]
25 | Literal[Literal[1], Literal[Literal[Literal[1]]]]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 |
27 | # OK
   |
help: Replace with flattened `Literal`
   |
24 | Literal[Literal[Literal[1], Literal[1]]]
   - Literal[Literal[1], Literal[Literal[Literal[1]]]]
25 + Literal[1, 1]
26 |
   |
