Skip to content

mypy doesnt use unitest.TestCase.assertIsInstance checks for type narrowing #13038

@rahulporuri

Description

@rahulporuri

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions