-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Allow using # type: ignore to skip type checking in a file #626
Comments
(Moved assignment and Milestone from the duplicate #964.) |
I wonder what we should do if this happens within a function. Should we then ignore all errors within the function only? Example:
This could be nice, as it would let people annotate functions but ignore errors in the body of the function. |
Yeah, I agree that this should be block-scoped. |
Hello, Alternatively, could there be a way to exclude certain files or directories from command line or in the configuration file? Currently, if I type In my case, I want to exclude automatically created Django migration files, but still scan my entire Django app. |
You can use the `ignore_errors` per-file option.
|
Thank you @gvanrossum, this seems to be what I was looking for. Could you please assist me a bit further? I tried to follow the instructions, but something is still not working: mypy.ini
$ mypy gw_box --ignore-missing-imports --config-file mypy.ini
gw_box/migrations/0001_initial.py:14: error: Need type annotation for variable |
You need to add a section like this:
For docs see http://mypy.readthedocs.io/en/latest/config_file.html |
Thank you, I figured out I was just missing the P.S. Just figured out who you were. Huge thank you for creating Python :) |
@ddfisher Are you planning to work on this? |
I would love to see this feature get implemented. In my tests I'm deliberately trying to break things, so being able to ignore the whole file is very useful. I'm currently using mypy.ini, but I'd much rather prefer adding a comment at the top of the file. |
Sorry we dropped the ball here -- we're a small team with many tasks. Do you want to try submitting a PR? |
Should there also be a |
That's not in the PEP, and presumably that should be done using one of the decorators already defined by the PEP for that purpose. |
|
I think we are pretty set on the syntax, as we don't want to make the parser implementation any more complicated for a special case. |
Hello folks, I've started using mypy (quite happily) but there are a few checks that I would like to ignore while not ignoring the entire file. It's not clear to me whether this is actually feasible as of now. For instance, I am using SQLlchemy and create model classes such as:
With this, mypy complains that I'd appreciate some feedback (might be doing something wrong here). Cheers, |
@Lawouach SQLAlchemy is special, since it uses a lot of dynamic magic. We are working on better support for it. For now you can just place |
Fantastic! I thought this was for the entire file but it's for the block only, right? |
A |
Gotcha! Thank you :) |
So is it still not possible to do this? I'm looking to disable mypy checking for tests and cannot find a good way to do this. |
@Beefy-Swain You can. See https://mypy.readthedocs.io/en/latest/config_file.html. |
I’m currently working on a PR for this. I should have something up in the next couple of days. |
Fixes #626 (There are potential further features as discussed in the PR, but these are somewhat controversial and may even be excised from PEP 484.)
Fixes python#626 (There are potential further features as discussed in the PR, but these are somewhat controversial and may even be excised from PEP 484.)
The proposed solution don't work in case the mypy.ini is being controlled by a different entity (DevOps for example). |
@danielbraun89 |
You can also use |
Both doesnt work for me, I guess the problem in my side |
I'm using 0.740 checking a Python 2 repo and neither [mypy]
mypy_path = ...
python_version = 2.7
disallow_any_unimported = false
disallow_any_decorated = true
disallow_untyped_calls = true
warn_redundant_casts = true
warn_unused_ignores = true
# HACK: Remove this as soon as possible
ignore_missing_imports = true |
It seems like a bug they fixed in 0.750(see #7789). We also found per file ignore not working in 0.740 and confirmed 0.750 have fixed this. |
How can I apply this to line 3 in the following code? Comments are not allowed here. I tried to add it after
|
The proposal for # type: ignore in the body of the function appears not to work yet: the below code errors with mypy 0.901
|
We gave up on that, it didn't seem all that important. |
As per PEP 484 discussion, it should be possible to use
# type: ignore
to skip type checking in the rest of a file:Currently the comment can only be used to ignore errors on individual lines.
The text was updated successfully, but these errors were encountered: