Skip to content

Disabling mypy for certain modules? #545

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

Closed
gvanrossum opened this issue Dec 22, 2014 · 4 comments
Closed

Disabling mypy for certain modules? #545

gvanrossum opened this issue Dec 22, 2014 · 4 comments

Comments

@gvanrossum
Copy link
Member

I thought it used to be the case that mypy only checked modules that explicitly import [from] typing. That gave a nice "out" for existing code that uses annotations with different conventions. But checking with the most recent version I found that it no longer does this -- all imported modules get checked, and all annotations it doesn't understand get flagged. I worry that this will upset people who have put efforts into their own system using annotation, and I think it's at least reasonable to be able to flag such code as "don't look here".

You can probably do this using a stub module, but perhaps it should be possible to just write something like

import foo  # type: Any

Or some other syntax at the importing site?

We can also think about disabling mypy checking for a smaller scope, e.g. a class or function -- maybe a class annotation @dont_type_check?

(Hm... Did I already bring this up earlier? If so please just close as duplicate.)

@refi64
Copy link
Contributor

refi64 commented Dec 22, 2014

I thought this was always a TODO?

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 29, 2014

Skipping type checking of modules that don't import typing has always been a TODO -- see #186. I bumped its priority since it will potentially simplify the adoption of mypy a lot. Further discussion on that aspect should happen there.

However, using # type: Any with imports is a good idea, and something like @dont_type_check would also be useful, so I'm keeping this issue open.

(Apologies if the above is incoherent. I'm traveling with kids in Europe and still a bit jet lagged.)

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 26, 2015

The PEP 484 sanctioned way to do this is to add # type: ignore close to the top of the file that shouldn't by type checked, or by adding # type: ignore to an import statement:

import foo  # type: ignore

I'm not sure if we should also support # type: Any with import statements.

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 29, 2015

This is now supported:

import foo  # type: ignore
foo.anything()

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

3 participants