Skip to content

assert False makes rest of function not checked by mypy #7467

@Hnasar

Description

@Hnasar

It seems when you have assert False, the rest of the function isn't checked.

x = 0
def foo_bad1():  # type: () -> str
    assert False
    return x
def foo_good():  # type: () -> str
    assert x
    return x
def foo_bad2():  # type: () -> str
    assert 0
    return x
  • What is the actual behavior/output?
$ mypy  foo2.py
foo2.py:7: error: Incompatible return value type (got "int", expected "str")
  • What is the behavior/output you expect?
$ mypy  foo2.py
foo2.py:4: error: Incompatible return value type (got "int", expected "str")
foo2.py:7: error: Incompatible return value type (got "int", expected "str")
foo2.py:10: error: Incompatible return value type (got "int", expected "str")
  • What are the versions of mypy and Python you are using?
    I tried with mypy 0.501, all the way up to 0.720, and also from git master.
    python 3.7.4 from Fedora 30.

  • What are the mypy flags you are using? (For example --strict-optional)
    none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions