---
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
---
PYI051 `Literal["foo"]` is redundant in a union with `str`
 --> PYI051.pyi:4:18
  |
2 | from typing import Literal, TypeAlias, Union
3 |
4 | A: str | Literal["foo"]
  |                  ^^^^^
5 | B: TypeAlias = typing.Union[Literal[b"bar", b"foo"], bytes, str]
6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
  |

PYI051 `Literal[b"bar"]` is redundant in a union with `bytes`
 --> PYI051.pyi:5:37
  |
4 | A: str | Literal["foo"]
5 | B: TypeAlias = typing.Union[Literal[b"bar", b"foo"], bytes, str]
  |                                     ^^^^^^
6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
  |

PYI051 `Literal[b"foo"]` is redundant in a union with `bytes`
 --> PYI051.pyi:5:45
  |
4 | A: str | Literal["foo"]
5 | B: TypeAlias = typing.Union[Literal[b"bar", b"foo"], bytes, str]
  |                                             ^^^^^^
6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
  |

PYI051 `Literal[5]` is redundant in a union with `int`
 --> PYI051.pyi:6:37
  |
4 | A: str | Literal["foo"]
5 | B: TypeAlias = typing.Union[Literal[b"bar", b"foo"], bytes, str]
6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
  |                                     ^
7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
8 | E: TypeAlias = typing.Union[typing.Union[typing.Union[typing.Union[Literal["foo"], str]]]]
  |

PYI051 `Literal["foo"]` is redundant in a union with `str`
 --> PYI051.pyi:6:67
  |
4 | A: str | Literal["foo"]
5 | B: TypeAlias = typing.Union[Literal[b"bar", b"foo"], bytes, str]
6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
  |                                                                   ^^^^^
7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
8 | E: TypeAlias = typing.Union[typing.Union[typing.Union[typing.Union[Literal["foo"], str]]]]
  |

PYI051 `Literal[b"str_bytes"]` is redundant in a union with `bytes`
 --> PYI051.pyi:7:37
  |
5 | B: TypeAlias = typing.Union[Literal[b"bar", b"foo"], bytes, str]
6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
  |                                     ^^^^^^^^^^^^
8 | E: TypeAlias = typing.Union[typing.Union[typing.Union[typing.Union[Literal["foo"], str]]]]
9 | F: TypeAlias = typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
  |

PYI051 `Literal[42]` is redundant in a union with `int`
 --> PYI051.pyi:7:51
  |
5 | B: TypeAlias = typing.Union[Literal[b"bar", b"foo"], bytes, str]
6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
  |                                                   ^^
8 | E: TypeAlias = typing.Union[typing.Union[typing.Union[typing.Union[Literal["foo"], str]]]]
9 | F: TypeAlias = typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
  |

PYI051 `Literal["foo"]` is redundant in a union with `str`
  --> PYI051.pyi:8:76
   |
 6 | C: TypeAlias = typing.Union[Literal[5], int, typing.Union[Literal["foo"], str]]
 7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
 8 | E: TypeAlias = typing.Union[typing.Union[typing.Union[typing.Union[Literal["foo"], str]]]]
   |                                                                            ^^^^^
 9 | F: TypeAlias = typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
10 | G: typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
   |

PYI051 `Literal["foo"]` is redundant in a union with `str`
  --> PYI051.pyi:9:81
   |
 7 | D: TypeAlias = typing.Union[Literal[b"str_bytes", 42], bytes, int]
 8 | E: TypeAlias = typing.Union[typing.Union[typing.Union[typing.Union[Literal["foo"], str]]]]
 9 | F: TypeAlias = typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
   |                                                                                 ^^^^^
10 | G: typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
   |

PYI051 `Literal["foo"]` is redundant in a union with `str`
  --> PYI051.pyi:10:69
   |
 8 | E: TypeAlias = typing.Union[typing.Union[typing.Union[typing.Union[Literal["foo"], str]]]]
 9 | F: TypeAlias = typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
10 | G: typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
   |                                                                     ^^^^^
11 |
12 | def func(x: complex | Literal[1J], y: Union[Literal[3.14], float]): ...
   |

PYI051 `Literal[1J]` is redundant in a union with `complex`
  --> PYI051.pyi:12:31
   |
10 | G: typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
11 |
12 | def func(x: complex | Literal[1J], y: Union[Literal[3.14], float]): ...
   |                               ^^
13 |
14 | # OK
   |

PYI051 `Literal[3.14]` is redundant in a union with `float`
  --> PYI051.pyi:12:53
   |
10 | G: typing.Union[str, typing.Union[typing.Union[typing.Union[Literal["foo"], int]]]]
11 |
12 | def func(x: complex | Literal[1J], y: Union[Literal[3.14], float]): ...
   |                                                     ^^^^
13 |
14 | # OK
   |
