meta-pytorch / meta-pytorch/data
Auto import variables for type annotation and default value for functional API during pyi gen
Nobody has claimed this yet.
- 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:
- Filter out duplicates if multiple files import the same thing
- Will we merge imports if they come from the same file (e.g. torch.utils.data)?
- (Optional) Avoid imports for objects that are defined in datapipe.py.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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