stubgen: unify C extension and pure python stub generators with object oriented design by chadrik · Pull Request #15770 · python/mypy

@chadrik chadrik changed the title stubgen: unify inspection and parsing based stub generators with object oriented design stubgen: unify C extension and pure python stub generators with object oriented design

Aug 1, 2023

chadrik

chadrik

chadrik

chadrik

JelleZijlstra

JelleZijlstra

@chadrik

@chadrik

@chadrik

@chadrik

@chadrik

@pre-commit-ci @chadrik

isbuiltin is isinstance(object, types.BuiltinFunctionType), and type(ord) is BuiltinFunctionType, so these conditions are the same

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

@chadrik

@chadrik

@chadrik

@chadrik

@JelleZijlstra @chadrik

JelleZijlstra pushed a commit that referenced this pull request

Nov 29, 2023
This addresses several regressions identified in
#16486

The primary regression from #15770 is
that pybind11 properties with docstrings were erroneously assigned
`typeshed. Incomplete`.

The reason for the regression is that as of the introduction of the
`--include-docstring` feature
(#13284, not my PR, ftr),
`./misc/test-stubgenc.sh` began always reporting success. That has been
fixed.

It was also pointed out that `--include-docstring` does not work for
C-extensions. This was not actually a regression as it turns out this
feature was never implemented for C-extensions (though the tests
suggested it had been), but luckily my efforts to unify the pure-python
and C-extension code-paths made fixing this super easy (barely an
inconvenience)! So that is working now.

I added back the extended list of `typing` objects that generate
implicit imports for the inspection-based stub generator. I originally
removed these because I encountered an issue generating stubs for
`PySide2` (and another internal library) where there was an object with
the same name as one of the `typing` objects and the auto-import created
broken stubs. I felt somewhat justified in this decision as there was a
straightforward solution -- e.g. use `list` or `typing.List` instead of
`List`. That said, I recognize that the problem that I encountered is
more niche than the general desire to add import statements for typing
objects, so I've changed the behavior back for now, with the intention
to eventually add a flag to control this behavior.

@chadrik chadrik deleted the stubgen/shared-sig-gen-mr branch

November 2, 2025 18:00