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

There should be a way to tell the type checker not to check (specific) 3rd party packages #53

Closed
gvanrossum opened this issue Jan 22, 2015 · 2 comments

Comments

@gvanrossum
Copy link
Member

Suppose I am writing an app using type hints but I am importing a 3rd party package that uses annotations for some other purpose. And suppose the author of that package isn't motivated to add # type: OFF comments to the top of every module, and I don't want to have to patch the package every time I install or upgrade it. Then there should be a way to tell the type checker not to check that package, or at least to ignore all annotations in it.

This can probably be a configuration option for the type checker, so perhaps this should be a mypy issue, not a PEP issue, but I think this would be a useful thing to mention in the PEP so people don't worry too much about 3rd party code using annotations for other purposes.

(An alternative would be not to type-check modules that don't import [from] typing, but I think that's limiting, because lots of code never needs any of the facilities defined there, it just wants to use annotations that use built-in types or locally-defined classes.)

@JukkaL
Copy link
Contributor

JukkaL commented Jan 28, 2015

Sounds reasonable. I added a mypy issue for this: python/mypy#562

I see three different categories of modules that don't import typing: (1) modules that don't import it and don't have any annotations, (2) modules that don't import it and have type annotations, either PEP 484 function annotations or # type: comments, (3) modules that don't import typing but have non-standard annotations. Should these all be different?

Mypy currently complains about code like this if there is no annotation, even for dynamically typed modules, since module top levels are implicitly statically typed by default:

x = []   # Can't infer the type of x

I'd like to change this so that mypy could process at least many existing modules and still support some level of type checking for code that imports those modules (e.g., checking that function argument counts are compatible).

Maybe category (1) modules should default to Any as the type of top-level and class variables, but mypy would try to infer these types for category (2) modules. Thus full type checking would be signalled by the addition of any type annotation or typing import. Most existing modules don't have any annotations, so a type checker could process them without generating errors, but marking a module for type checking wouldn't need to involve importing typing. Category (3) modules would need either a # type: OFF comment or telling the type checker to not to check that module.

@gvanrossum
Copy link
Member Author

Moved to README.rst.

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

No branches or pull requests

2 participants