Skip to content

report error for false type assertions #4306

Closed
@chadrik

Description

@chadrik

I'm currently adding annotations to a complex module, and even after resolving most of the mypy errors within the module I suspect there are still quite a few inaccurately typed functions due to corner-cases which will only be detected in code that uses the module in specific ways. I already have unittests for this module (written using pytest) that do precisely this, so type checking these would be the ideal way to check my annotations -- all-in-one static and runtime analysis.

It would go a long way to easing adoption if mypy raised errors on type assertions that it can detect are false. e.g.:

i = 0
assert isinstance(i, str)  # error
assert type(i) is str  # error

Bonus points for supporting the python unittest module's assert*() methods, but most people these days are using pytest and as a feature request it seems much easier and more useful to simply support assert.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions