-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Excluding a protobuf directory from mypy in pyproject.toml
& pre-commit-config.yaml
#16403
Comments
It might help if you can pare down a smaller sample that reproduces the issue? |
Yes, you should generate type-compatible stubs using the |
Thanks @erictraut, I've now done so, not sure it's correct, but I used:
Surely this could be done with one tool? |
@posita I'll try and simplify it, I have: ├── proto
│ ├── __init__.py
│ ├── zkp_auth_pb2_grpc.py
│ ├── zkp_auth_pb2.py
│ ├── zkp_auth_pb2.pyi
│ └── zkp_auth.proto
├── src
│ ├── __init__.py
│ ├── __main__.py
│ ├── client.py
│ └── server.py
├── poetry.lock
└── pyproject.toml And when running I would thus like to exclude that particular file from having I tried setting this in both my Could you please kindly advise how one can go about correctly ignoring either the specific file mentioned, or the whole |
@BenWolfaardt, I meant four, very brief files:
I assume, given the above that the expected result of running |
I think we can extend this to mypy.ini exclude regex's don't work, at least in the non regex form. On top of this, even the simple example in the docs isn't working for me
^ weirdly it returns success, but nothing is actually linted. However, the below worked (in the pyproject.toml)
|
Configure your pre-commit hook like this: - repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
- id: mypy
language: system
pass_filenames: false
args: ['.'] Now you're able to correctly set all configurations in your
|
@jsimonlane, what does "in the non regex form" mean in this context? If the doc's examples aren't working, that sounds like a regression (see, e.g., this test). Do we need to file another issue? @BenWolfaardt's original issue was about calling Mypy from pre-commit using UPDATE: The
|
@BenWolfaardt, I think I might see the issue.
I think this is by design, but haven't researched it. I'm also guessing I see you have one already, but I'm not sure this is a Mypy bug if
|
Hi @posita , please take a look on this answer: #16403 (comment) |
I saw that. Does that mean this issue should be closed? As an aside, I think that work-around works because it (in effect) tells |
@posita, looking further it seems that the parser actually works correctly... though it is confusing, as I'm seeing text So it looks like the functionality works... but odd I'm seeing the error. Basically, when I run mypy with a multi-line regex, I get the error: When I use a regular (single-line) regex, excluding works. I also tried this on version 1.70 just now, same issue.
|
@jsimonlane, |
I agree with @posita. Could @BenWolfaardt solve his problem with the configuration suggested in this thread? |
I also had the same problem. The solution #16403 (comment) is not the best for me, because as said before, it affects all files in the project, which is not always necessary |
Hey there. I did it this way: mypy config in [tool.mypy]
# ...
exclude = [
"tests",
] This works when running mypy manually: mypy ./ And for repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
exclude: tests |
See also: #13916 |
Closing per my comment, use |
Hey all, thanks for the great product, my code quality has significantly improved since I started using
mypy
.I've, however, been struggling all day trying to get
mypy
to ignore the automatically generatedprotobuf
files - ending with<filename>_pb2.py
and<filename>_pb2_grpc.py
due to the fact that these files are auto-generated and that we shouldn't be editing them as per:# Generated by the protocol buffer compiler. DO NOT EDIT!
I would like to exclude them. This in and of itself is difficult, let alone trying to get it to happen when running
mpy
in your CLI as well as in youpre-commit
... I've read everything I can find:python/mypy
My current config:
Python
3.11.4
pre-commit-config.yaml
pyproject.toml
The structure of my project is:
. ├── ci │ ├── Dockerfile-client │ └── Dockerfile-server ├── docker-compose.yml ├── poetry.lock ├── proto │ ├── __init__.py │ ├── zkp_auth_pb2_grpc.py │ ├── zkp_auth_pb2.py │ ├── zkp_auth_pb2.pyi │ └── zkp_auth.proto ├── pyproject.toml ├── README.md ├── scripts │ └── setup.sh ├── src │ ├── client.py │ ├── __init__.py │ ├── __main__.py │ └── server.py └── tests
A few of the things I tried (excuse my use of
regex
I'm still very new to it) in mypyproject.toml
are:Furthermore I tried:
mypy.ini
file insteadpre-commit-config.yaml
with regards to the arguments being parsed to itpass_filenames: false
The part I also don't get is that I was able to commit the auto-generated files even if they had issues, think I had
exclude: proto/
in mypre-commit
that time, but then that the other files importing these auto-generated protobuf files would result in issues when committing, example:Do I potentially need to use: https://github.com/nipunn1313/mypy-protobuf?
@posita I hope you don't mind me tagging you as p[er your post here
The text was updated successfully, but these errors were encountered: