You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.)
The text was updated successfully, but these errors were encountered:
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.
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.)
The text was updated successfully, but these errors were encountered: