Skip to content

Better handling of hidden builtins#278

Open
skarndev wants to merge 16 commits intopybind:mainfrom
skarndev:master
Open

Better handling of hidden builtins#278
skarndev wants to merge 16 commits intopybind:mainfrom
skarndev:master

Conversation

@skarndev
Copy link
Contributor

@skarndev skarndev commented Jan 17, 2026

Added a generalized algorithm to handle builtins exposed via the types module, but reporting builtins at introspection.

Why

Importing types, via pybind11 such as py::module::import("types").attr("MappingProxyType") currently yields an unresolved name "mappingproxy" in the generated .pyi stubs.
The reason for this is that the MappingProxyType.__qualname__ at runtime is "mappingproxy" and __module__ is "builtins". However, the actual builtins module does not expose this as an importable attribute.

There are a number of other "hidden" builtins that follow this pattern. They all seem to come from the types module. I also left room for overriding this behavior, as was done before for "function" and "builtin_function_or_method".

Added a generalized algorithm to handle builtins exposed via the 
`types` module, but reporting `builtins` at introspection.
@ax3l ax3l requested review from ax3l and virtuald January 22, 2026 07:44
@ax3l ax3l added the bug Something isn't working label Jan 22, 2026
@skarndev
Copy link
Contributor Author

Test cases for this also need to be added.

@skarndev skarndev marked this pull request as draft January 22, 2026 18:48
@ax3l ax3l mentioned this pull request Jan 23, 2026
18 tasks
@skarndev
Copy link
Contributor Author

I added missing stubs and a few more test cases to cover this.
I did not add builtin_function_or_method though as I was not able to make pybind11 to produce such as a signature. Does anybody know a way to do that?
Perhaps @sizmailov, since you wrote the original overrides for these.

@skarndev skarndev marked this pull request as ready for review January 29, 2026 12:02
@skarndev skarndev self-assigned this Jan 30, 2026
@pybind pybind deleted a comment from skarndev Feb 5, 2026
@ax3l ax3l removed their request for review February 5, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants