PyCQA/flake8-bugbear

New check: duplicate types in type hint, or duplicate literals in set

Offen

#371 geöffnet am 21.03.2023

 (5 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Python (116 Forks)github user discovery
enhancementhelp wanted

Repository-Metriken

Stars
 (1.116 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 4h 17m) (3 gemergte PRs in 30 T)

Beschreibung

a: int | int | float = ...
b: Union[List[int, int]] = ...
c: Optional[int] | int | None = ... # can probably rely on other linters to not have to deal with this one
d: set[int] = {1, 2, 3, 3, 5}

e: Tuple[int, int] = ... # not an error

these should pretty much always be typos and/or bad copy-pastes, with very few to no false alarms. Don't think it's super common, but definitely not rare or super esoteric.

The check shouldn't have to be too complicated to implement, for the type hint probably need a whitelist of what types you look in (List/list, Set/set, Dict/dict (with special logic), OrderedDict, Optional, Union, Literal...).

For sets you only need to look inside set() (ast.Call) and inside {} (ast.Set), and probably only include literal int/float/strings.

Contributor Guide