data
data copied to clipboard
Auto import variables for type annotation and default value for functional API during pyi gen
🚀 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