mypy doesnt use unitest.TestCase.assertIsInstance checks for type narrowing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Apologies if i'm using the wrong words to describe what i'm trying to recommend/request.
Feature
At the moment, mypy recommends type narrowing using asserts. For example, if something is Optional[None], add assert something is not None to help mypy type check the statements that follow the assert.
In tests, instead of adding an additional assert, can mypy use a unittest.TestCase.assertIsInstance check?
Pitch
Most unittest-based tests already make use of the assertIsInstance check so we can prevent the need to add an additional assert or the need to convert the assertIsInstance into a assert isinstance(something) is sometype.
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
No file, test, or entry point is named in the issue. Start by tracing mypy's existing handling of unittest.TestCase.assertIsInstance and its type-narrowing logic, then identify the appropriate regression-test area. Done means supported assertIsInstance checks narrow types without an additional assert and are covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100