meta-pytorch / meta-pytorch/data

Auto import variables for type annotation and default value for functional API during pyi gen

Open
#726 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Better Engineering
Dominant language
Python
Stars
1.3k
Forks
179
Avg merge
6d 1h
Merged PRs (30d)
2

Description

🚀 The feature

When we generate the interface of functional API, we can scan __init__ function for all type annotation and default variables that are imported from somewhere by the file itself. Then, we don't need to manually update the stub file with hard coded import statements whenever a new dependency is introduced to interface.

In order to achieve so, we need to make sure it works with the following considerations:

  1. Filter out duplicates if multiple files import the same thing
  2. Will we merge imports if they come from the same file (e.g. torch.utils.data)?
  3. (Optional) Avoid imports for objects that are defined in datapipe.py.
  4. Import the default variable from the same file of the DataPipe. Needs to figure out the file path by pyi gen.
Motivation, pitch
  • For torchdata contributors, we don't need to always check if there is new variables needed for pyi file when we implement a new DataPipe. Without importing the corresponding variables, mypy would raise complains, which are sometimes hard to interoperate for the first-time contributor.
Alternatives

No response

Additional context

cc: @NivekT

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the pyi gen entry point and reviewing torchdata/datapipes/iter/init.pyi.in, including its hard-coded imports. Compare that with datapipe.py and the init functions whose annotations and defaults are scanned. Done means generated stubs add required imports automatically, remove duplicates, and handle imports from the DataPipe's file.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.