Skip to content

Can't fully ignore file with syntax error generated from mypy-protobuf library #6897

Closed
@gaggle

Description

@gaggle

Bug. I think. This may be intended behaviour, but in that case it's problematic. I think my question is related to, but not a duplicate of, #6155

Using https://github.com/dropbox/mypy-protobuf/ I generate Protobuf .pyi files. I don't want mypy to analyze these files because they are autogenerated, but mypy seems unable to fully exclude a file when it has syntax errors.

This is the exact error from mypy:

$ mypy --cache-dir=/dev/null package --ignore-missing-imports --follow-imports=skip
package/schemas/foo_pb2.pyi:356: error: invalid syntax

This is a snippet of package/schemas/foo_pb2.pyi file:

class ListCrawlResourcesRequest(google___protobuf___message___Message):
    limit = ... # type: int
    from = ... # type: int

    @property
    def filter(self) -> CrawlResourcesFilter: ...

    def __init__(self,
        limit : typing___Optional[int] = None,
        from : typing___Optional[int] = None,
        ) -> None: ...

Notice the from = ..., that's straight from the mypy-protobuf output but it's invalid Python. That doesn't appear to be a real problem in a .pyi file, but the problem is mypy can't seem to fully ignore checking this file.

This is my mypy.ini:

[mypy]

[mypy-package.schemas.*]
ignore_errors = True

This file works, in so far that without the .pyi files errors are ignored in the remaining pb2.py files. But the above syntax error is not ignored. I assume ignore_errors only ignores errors but not syntax errors? I went looking for an ignore_syntax_errors = True flag but that does not appear to exist.

I'm using versions:

$ python --version Python 3.6.7
mypy==0.701

I'm running mypy using this command:

mypy --cache-dir=/dev/null package --ignore-missing-imports --follow-imports=skip

Here is a gist with the entire contents of the .proto file, the generated (and successfully excluded) .py file, and the problematic and unexcludable .pyi file:
https://gist.github.com/gaggle/8aef6102d314936c9eb33724194682b0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions