Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Wrong type annotation when using std::filesystem::path as a return type, causes stubgen to choke #5477

Open
2 of 3 tasks
HolyBlackCat opened this issue Dec 24, 2024 · 3 comments · May be fixed by #5486
Open
2 of 3 tasks
Labels
triage New bug, unverified

Comments

@HolyBlackCat
Copy link

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

741d86f

Problem description

When a function returns std::filesystem::path and I use <pybind11/stl/filesystem.h>, the type annotation says Path, which is a non-existent type, which makes pybind11_stubgen choke on such functions.

Previous versions of Pybind used to return os.PathLike, but this was broken in #5450.

Reproducible example code

No response

Is this a regression? Put the last known working version here if it is.

2.10.1

@timohl
Copy link
Contributor

timohl commented Dec 24, 2024

Thanks for reporting.
Could you provide the error message and version of pybind11-stubgen?

I thought I tested this and pybind11-stubgen imports it automatically, but maybe we have to go with pathlib.Path.

@HolyBlackCat
Copy link
Author

Stubgen says pybind11_stubgen - [ ERROR] In my_module.my_function : Can't find/import 'Path' for every function that returns std::filesystem::path.

pip show pybind11-stubgen says the version is 2.5.1.

I don't know its inner workings too well, but how would it guess that Path means pathlib.Path?

@timohl timohl linked a pull request Jan 6, 2025 that will close this issue
4 tasks
@timohl
Copy link
Contributor

timohl commented Jan 6, 2025

I added a fix for this in my latest PR reworking the arg/return type hint system.
If this PR takes too long or gets rejected, I can create a small PR only containing the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants