Mypy: Can't fully ignore file with syntax error generated from mypy-protobuf library

Created on 23 May 2019  路  3Comments  路  Source: python/mypy

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

needs discussion topic-usability

Most helpful comment

Sometimes bug reports can read so negative, so let me just say huge thanks to contributors for making mypy available, love it to bits.

All 3 comments

Sometimes bug reports can read so negative, so let me just say huge thanks to contributors for making mypy available, love it to bits.

Unfortunately the way .pyi files are parsed makes it hard to fix this, even if it is a bug. (I think it's probably undefined.)

In the meantime, can you report the problem with the mypy-protobuf project? The .py generator for protobuf files must be able to generate code for this without syntax errors (presumably by renaming the variable somehow), and mypy-protobuf should follow its lead.

Ignoring syntax errors would be hard to support in a useful way, since we'd have no AST to work with. I don't think there's anything straightforward we can do here (other than completely ignoring the file, which seems dangerous).

Was this page helpful?
0 / 5 - 0 ratings