Feature request: option that completely disallows typing.cast
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Feature
An option that disallows use of typing.cast, eg --disallow-casts
Pitch
cast() gets around static type safety without ensuring dynamic type correctness. Sometimes you have to use it—you know how it is—but it's not ideal. (For instance, mypy documentation seems to imply the main use of cast is when the typechecker or type annotations aren't quite good enough.) That means, in my opinion, cast is a great candidate to have a option disallowing its use, to ensure code quality in codebases where it is not needed.
I also think this option should be enabled in strict mode, but I suspect other people might disagree.
This proposal is distinct from the --warn-redundant-casts option that already exists, but is somewhat similar.
Contributor guide
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 reviewing how the existing --warn-redundant-casts option is implemented and read the discussion about whether this belongs in strict mode. Define the intended handling of typing.cast and its configuration behavior, then verify that the new option rejects casts and that the chosen strict-mode behavior is covered by tests.
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
- 35/100