Skip to content

Commit 8f94d9a

Browse files
authored
Improvements to stubgenc (#14564)
This bundles together a handful of improvements to stubgenc. Each one has its own commit, but it can be somewhat time consuming to get a PR reviewed and merged, so I'm putting them together for the sake of expediency. I'll break them up if it is preferred. An overview of the main changes: - infer return types for known special methods: previously only argument types were inferred - check class docstrings for signatures in addition to `__init__`: shiboken binding generator is known to put constructor signatures in class docstrings rather than on `__init__` - use the list of analyzed modules to produce better imports: previously when given `foo.Bar.Spangle`, it was assumed that `import foo.Bar` should be added, however, it could be that `Bar.Spangle` refers to nested classes within the module `foo`. - when fixing up types, also process children of compound types - evaluate descriptors when getting members: necessary for shiboken bindings
1 parent 1a47b19 commit 8f94d9a

File tree

3 files changed

+373
-147
lines changed

3 files changed

+373
-147
lines changed

mypy/stubgen.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,7 @@ def generate_stubs(options: Options) -> None:
17201720
)
17211721

17221722
# Separately analyse C modules using different logic.
1723+
all_modules = sorted(m.module for m in (py_modules + c_modules))
17231724
for mod in c_modules:
17241725
if any(py_mod.module.startswith(mod.module + ".") for py_mod in py_modules + c_modules):
17251726
target = mod.module.replace(".", "/") + "/__init__.pyi"
@@ -1728,7 +1729,9 @@ def generate_stubs(options: Options) -> None:
17281729
target = os.path.join(options.output_dir, target)
17291730
files.append(target)
17301731
with generate_guarded(mod.module, target, options.ignore_errors, options.verbose):
1731-
generate_stub_for_c_module(mod.module, target, sig_generators=sig_generators)
1732+
generate_stub_for_c_module(
1733+
mod.module, target, known_modules=all_modules, sig_generators=sig_generators
1734+
)
17321735
num_modules = len(py_modules) + len(c_modules)
17331736
if not options.quiet and num_modules > 0:
17341737
print("Processed %d modules" % num_modules)

0 commit comments

Comments
 (0)