reportUnknownParameterType and 3rd party libraries #2376
-
My current codebase works with a lot of untyped python libraries. The libraries are large enough (tensorflow, apache beam) that type hinting a meaningful portion of them looks fairly time consuming. At the same time I want all code within my team's codebase to be fully type hinted. The challenge is writing type hints like this, from untyped_library import Foo
def f(x: Foo) -> None
... I want that to type check. I currently get a type error of unknown parameter type. Dropping that rule is undesirable when missing type for an argument/return I consider an error. I effectively want all types from untyped libraries to be treated as Any instead of unknown. I did find one sorta workaround which was add a typings folder and add untyped_library/init.pyi with, from typing import Any
def __getattr__(name: str) -> Any:
... This has one major downside. Before I added this while Foo was unknown I could double click on Foo and it'd jump to where it was defined. Now I add this and it loses that ide navigation. For mypy I'm able to have things work with configuration of,
The getattr solution is very close to that and from a CI perspective works. It worsens the IDE experience as it loses the original definition. Between losing IDE powers vs many type ignores neither looks good and I'm undecided which I'll pick. For a concrete example I think any untyped library should work and explore import of navigation with typings. One specific one I've used,
and then trying typings/apache_beam/pipeline.pyi with getattr contents. To install that library from untyped_library import Foo
def f(x) -> None
... and from untyped_library import Foo
def f(x: Foo) -> None
... are both type errors even though second is an improvement to me from the first. Some way to distinguish the two in reporting errors would be very helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I discussed this with my colleagues, and we think there's merit in adding a new diagnostic check for |
Beta Was this translation helpful? Give feedback.
I discussed this with my colleagues, and we think there's merit in adding a new diagnostic check for
reportMissingParameterType
. I'll create an enhancement request that links to this discussion.