Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stubgen: fixes and simplifications (#15232)
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