Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stubgen: multiple fixes to the generated imports #15624

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

hamdanal
Copy link
Collaborator

@hamdanal hamdanal commented Jul 8, 2023

  • Fix handling of nested imports.
    Instead of assuming that a name is imported from a top level package, look in the imports for this name starting from the parent submodule up until the import is found
  • Fix "from imports" getting reexported unnecessarily
  • Fix import sorting when having import aliases

Fixes #13661
Fixes #7006

* Fix handling of nested imports
  Instead of assuming that a name is imported from a top level package,
  look in the imports for this name starting from the parent submodule
  up until the import is found
* Fix "from imports" getting rexported unnecessarily
* Fix import sorting when having import aliases

Fixes python#13661
Fixes python#7006
@hamdanal
Copy link
Collaborator Author

Please note that this has been tested with a mypy_primer-like script that I wrote locally for stubgen. The script was run on a bunch of packages from the scientific suite (matplotlib, numpy, pandas, seaborn, scipy). I inspected all the changes in the output one by one and they were all correct. It removed a bunch of unnecessary re-exports and added a single missing nested import in matplotlib. So overall I am confident with this change.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not the most familiar with stubgen but) this looks great, thanks! And awesome to hear about your stubgen primer

@hauntsaninja hauntsaninja merged commit 0c8b761 into python:master Sep 25, 2023
13 checks passed
@hamdanal hamdanal deleted the stubgen-imports branch September 25, 2023 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants