stubgen: fixes and simplifications #15232
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:get_fullname
method that resolves the full name of bothNameExpr
andMemberExpr
taking into account import aliasesprocess_decorator
,process_name_expr_decorator
, andprocess_member_expr_decorator
into a single method thanks to the common name resolution usingget_fullname
Incomplete
from_typeshed
) by usingself.typing_name()
andself.add_typing_import
which take into account objects of the same name defined in the fileOut 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 casetestUseTypingName
demonstrates point4.
. In existing test cases, only white space changes in four of the cases due to point5.
above were made.This will allow easier additions in the future as no manual name resolution has to be made any more.