Skip to content

Commit

Permalink
stubgen: fixes and simplifications (python#15232)
Browse files Browse the repository at this point in the history
This PR refactors name resolution in stubgen to make it simple to use
and fixes a bunch of related bugs especially when run in `--parse-only`
mode. It mainly does the following:
1. Adds a `get_fullname` method that resolves the full name of both
`NameExpr` and `MemberExpr` taking into account import aliases
2. Use this method everywhere manual resolution was done including the
decorator processors
3. Simplify decorator processing by consolidating `process_decorator`,
`process_name_expr_decorator`, and `process_member_expr_decorator` into
a single method thanks to the common name resolution using
`get_fullname`
4. Fix occurrences of some hard-coded implicitly-added names (like
`Incomplete` from `_typeshed`) by using `self.typing_name()` and
`self.add_typing_import` which take into account objects of the same
name defined in the file
5. Fix some inconsistencies in generated empty lines. This improves the
consistency within stubgen as well as with the black code style for
stubs.

Out of the 9 test cases added, only `testAbstractPropertyImportAlias`
passes on master (added it any way because it was not tested). The other
8 all fail without this PR. The last test case `testUseTypingName`
demonstrates point `4.`. In existing test cases, only white space
changes in four of the cases due to point `5.` above were made.

This will allow easier additions in the future as no manual name
resolution has to be made any more.
  • Loading branch information
hamdanal authored May 18, 2023
1 parent 24b585f commit d98cc5a
Show file tree
Hide file tree
Showing 2 changed files with 337 additions and 261 deletions.
Loading

0 comments on commit d98cc5a

Please sign in to comment.