Skip to content

Conversation

@gentlegiantJGC
Copy link
Contributor

Types like union types have nested types in them.
The current implementation only removes the current module name from the root type name.
This modifies that behaviour so that it expands nested types recursively.
I discovered this through a mypy error that the module had not been imported.

Current behaviour

class Foo:
    pass

def test(arg: list[module.Foo] | module.Foo]) -> None: ...

Expected behaviour

class Foo:
    pass

def test(arg: list[Foo] | Foo]) -> None: ...

* Remove current module from nested types

Types like union types have nested types in them.
The current implementation only removes the current module name from the root type name.
This modifies that behaviour so that it expands nested types recursively.

* Add tests

* Reorder variant types

pybind11 requires that arguments are default constructable but Foo is not

* Reorder types in union

* Add nested types to all

* Add missing stubs
@ax3l
Copy link
Contributor

ax3l commented Jan 22, 2026

Oh I had a couple of issues like these recently and started patching around.

Thank you for the fix @gentlegiantJGC!

Can you please rebase against master and force-push, to re-run CI?

@ax3l ax3l added the bug Something isn't working label Jan 22, 2026
@ax3l
Copy link
Contributor

ax3l commented Jan 22, 2026

Per #266 (comment), the PR in #263 might be the simpler fix.

@ax3l
Copy link
Contributor

ax3l commented Jan 22, 2026

Moved into #280

@ax3l ax3l closed this in #280 Jan 22, 2026
ax3l added a commit to juelg/pybind11-stubgen that referenced this pull request Jan 22, 2026
Fixes pybind#266
Fixes pybind#272

Takes the tests from pybind#272 and the simple fix from the large PR in pybind#263.
Credits to @gentlegiantJGC and @sarlinpe 🙏

---------

Co-authored-by: gentlegiantJGC <gentlegiantJGC@users.noreply.github.com>
Co-authored-by: sarlinpe <paul.edouard.sarlin@gmail.com>
Co-authored-by: Skarn <skarnproject@gmail.com>
@gentlegiantJGC gentlegiantJGC deleted the fix-nested-qualname branch January 23, 2026 08:07
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