data icon indicating copy to clipboard operation
data copied to clipboard

Include `py.typed` marker file for mypy type hint compatibility

Open kiukchung opened this issue 3 years ago • 3 comments

🚀 The feature

From what I can tell torchdata actually had type stubs but mypy won't pick it up because it is missing the py.typed marker file (see: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker)

The ask is to add py.typed to the package data similar to how torch does it so that projects using torchdata can have mypy recognize torchdata modules type hints.

Motivation, pitch

My project uses torchdata and also uses mypy for static type checking. Since mypy does not pick up torchdata's type stubs I get an error as:

mfive/datapipes/amzn/datakit.py:9:1: error: Skipping analyzing "torchdata.datapipes": module is installed, but missing library stubs or py.typed marker  [import]

Alternatives

I could add a ignore-missing-imports in my mypy.ini file:

[mypy-torchdata.*]
ignore_missing_imports = True

But that means that all the torchdata related types will be typed as Any, hence not letting me enable checks like disallow_subclassing_any=True if I'm writing my own custom datapipe that subclasses torchdata.datapipes.iter.IterDataPipe.

Additional context

No response

kiukchung avatar Sep 17 '22 04:09 kiukchung

Sounds like a reasonable request. Sending a patch shortly.

ejguan avatar Sep 19 '22 13:09 ejguan

Awesome, I can confirm mypy is able to get type hints for torchdata from my project. Will depend on the nightly until a dot release. Any ideas on when 0.4.2 will be released?

kiukchung avatar Sep 19 '22 23:09 kiukchung

@kiukchung I am sorry that I have to revert the PR until we fix the wrong typing in torchdata. See: https://github.com/pytorch/data/issues/782

And, in terms of the official release, it should be happen in the a 1/2 months aligned with PyTorch Core.

ejguan avatar Sep 20 '22 16:09 ejguan