Skip to content

Mypy could be clearer that an invalid type comment or annotation prevents it from scanning the rest of the project #3850

Closed
@marmistrz

Description

@marmistrz

TL;DR: some errors prevent mypy from further checking the project and this should be clearly stated in the log.

I was trying to add mypy type-checks to a big Python project. The branch I reproduced this problem on is: https://github.com/marmistrz/golem/blob/mypy-quirks

There's a defective function here which is properly linted with

$ mypy --ignore-missing-imports --strict-optional golem/model.py
golem/model.py:143: error: Item "None" of "Optional[Node]" has no attribute "to_json"

But now any of these:

mypy golem --ignore-missing-imports --strict-optional
mypy -m golem --ignore-missing-imports --strict-optional
mypy -p golem --ignore-missing-imports --strict-optional

doesn't yield that result (the variants golem and -p golem yield other errors but not this, -m golem yields no results)

What's more interesting, if I run

mypy golem/network --ignore-missing-imports --strict-optional

the same error, in golem/model.py is detected! Even an xargs invocation failed...

What was the problem? The second error message!

golem/core/async.py:34: error: Name 'default_errback' already defined on line 17
apps/rendering/resources/imgrepr.py:181: error: invalid type comment or annotation

The annotation was indeed incorrect:

def load_as_PILImgRepr(file_) -> PILImgRepr():

The second error made mypy abort further checking. It should be stated more clearly that this error prevents further scanning (e.g. even with capitals). This is very important when introducing incremental linting (only banning new findings) and it really puzzled me for some time that my mistake was not detected.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions