I wonder what we should do if this happens within a function. Should we then ignore all errors within the function only? Example:
def f() -> None:
# type: ignore
return 1 + 'x' # don't report an error?
a = 1 + 'y' # report an error here?
This could be nice, as it would let people annotate functions but ignore errors in the body of the function. @no_type_check is not a good match, as it also causes the annotations to be ignored.
Alternatively, could there be a way to exclude certain files or directories from command line or in the configuration file?
Currently, if I type mypy my_directory, the entire folder is scanned. It would be very handy to be able to add an --exclude argument.
In my case, I want to exclude automatically created Django migration files, but still scan my entire Django app.
Reacted by Leah Einhorn, Eduardo Gonçalves, Yanlei Zhao, Marius-Constantin Melemciuc, Ching C, Brad Holmes, Daniel Brown, TheSnoozer, Chao Wang, Marco Edward Gorelli and 2 more
The proposed solution don't work in case the mypy.ini is being controlled by a different entity (DevOps for example).
There is certainly a need for a local solution
You can also use # mypy: ignore-errors at the top of the file.
Reacted by Farzad Senart, Byeonghoon Yoo, Changsheng Wu, Yuki Yokoyama, Matt Parker, Dmytro Osaulenko, Cihat Imamoglu, Ben Wallace, RagetyDev, Patrick Seidensal and 8 more
I'm using 0.740 checking a Python 2 repo and neither # type: ignore nor # mypy: ignore-errors at the top of a file work for me. My configuration looks like this:
I'm using 0.740 checking a Python 2 repo and neither # type: ignore nor # mypy: ignore-errors at the top of a file work for me. My configuration looks like this:
Activity
gvanrossum commented on Jul 29, 2016
(Moved assignment and Milestone from the duplicate #964.)
JukkaL commented on Aug 17, 2016
I wonder what we should do if this happens within a function. Should we then ignore all errors within the function only? Example:
def f() -> None: # type: ignore return 1 + 'x' # don't report an error? a = 1 + 'y' # report an error here?This could be nice, as it would let people annotate functions but ignore errors in the body of the function. @no_type_check is not a good match, as it also causes the annotations to be ignored.
gvanrossum commented on Aug 17, 2016
Yeah, I agree that this should be block-scoped.
syenchuk commented on Feb 14, 2017
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 mypy my_directory, the entire folder is scanned. It would be very handy to be able to add an --exclude argument.
In my case, I want to exclude automatically created Django migration files, but still scan my entire Django app.
gvanrossum commented on Feb 14, 2017
syenchuk commented on Feb 14, 2017
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
gvanrossum commented on Feb 14, 2017
You need to add a section like this:
For docs see http://mypy.readthedocs.io/en/latest/config_file.html
syenchuk commented on Feb 14, 2017
Thank you, I figured out I was just missing the mypy- part.
P.S. Just figured out who you were. Huge thank you for creating Python :)
JukkaL commented on May 31, 2017
@ddfisher Are you planning to work on this?
13 remaining items
benjamin-kirkbride commented on May 11, 2019
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.
mitar commented on May 12, 2019
@Beefy-Swain You can. See https://mypy.readthedocs.io/en/latest/config_file.html.
brandtbucher commented on May 12, 2019
I’m currently working on a PR for this. I should have something up in the next couple of days.
Ignoring a file with a single # type: ignore comment. (#6830)
Ignoring a file with a single # type: ignore comment. (python#6830)
danielbraun89 commented on Jul 22, 2019
The proposed solution don't work in case the mypy.ini is being controlled by a different entity (DevOps for example).
There is certainly a need for a local solution
JukkaL commented on Jul 22, 2019
@danielbraun89 # type: ignore comment at the beginning of the file is now supported. Does it not work for you?
gvanrossum commented on Jul 22, 2019
You can also use # mypy: ignore-errors at the top of the file.
danielbraun89 commented on Jul 23, 2019
Both doesnt work for me, I guess the problem in my side
dargueta commented on Nov 25, 2019
I'm using 0.740 checking a Python 2 repo and neither # type: ignore nor # mypy: ignore-errors at the top of a file work for me. My configuration looks like this:
kkpattern commented on Dec 10, 2019
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.
nedrebo commented on Apr 3, 2020
How can I apply this to line 3 in the following code? Comments are not allowed here. I tried to add it after """ on line 7, but that didn't work.
1: return f""" 2: {'constexpr' if self.is_constexpr() else ''} ValueType verifyValue({argument}) {{ 3: return ({self.value_in_range_expression()}) 4: ? {return_value} 5: : throw std::out_of_range("{self.out_of_range_exception_message()}"); 6: }} 7: """ikamensh commented on Jun 9, 2021
The proposal for # type: ignore in the body of the function appears not to work yet:
the below code errors with mypy 0.901
def my_sum(*args: int) -> int: return sum(args) def other() -> None: # type: ignore print(my_sum("1", 2))gvanrossum commented on Jun 9, 2021
We gave up on that, it didn't seem all that important.