New check: duplicate types in type hint, or duplicate literals in set
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 123
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 5
Description
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
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing AST-based checks and their tests in the repository; the issue does not name specific files or entry points. Implement coverage for duplicate types in the listed type-hint containers and duplicate literal values in set() and set literals, then verify the examples distinguish errors from the Tuple case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100