Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gaggle opened this issue May 23, 2019 · 3 comments
Closed

Comments

@gaggle
Copy link

gaggle commented May 23, 2019

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

@gaggle
Copy link
Author

gaggle commented May 23, 2019

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

@gvanrossum
Copy link
Member

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.

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 29, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants