-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(types): render typed iterators in make_*iterator
doc
#4876
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. It's a very small change, based on what we have now.
FYI: I just initiated Google-global testing for this PR. Mainly to see how many stubgen-generated .pyi files need to be updated. BTW: When I deployed PRs #4831 & #4833 (in one combined update) I had to update 50 .pyi around the codebase, which was very unusual, but also not surprising (because #4833 changed |
I will have to update 2 .pyi files. I inspected the auto-generated changes and they look like a nice cleanup, e.g. - def keys(self) -> Iterator: ...
- def values(self) -> Iterator: ...
+ def keys(self) -> Iterator[str]: ...
+ def values(self, *args, **kwargs) -> Any: ...
- def __iter__(self) -> Iterator: ...
+ def __iter__(self) -> Any: ... I'll go ahead with merging this PR. |
Note for completeness: The 🐍 3.9-dbg (deadsnakes) • Valgrind • x64 CI failure is unrelated. First observed 2023-10-16 (yesterday). |
@rwgk Thank you! TBH I expected more files to be affected. Probably Google's code base does not expose many iterators. The diff doesn't look like a 100% improvement to me. The following stub got worse, but it's an issue of binding code, not pybind11. - def values(self) -> Iterator: ...
+ def values(self, *args, **kwargs) -> Any: ... I would speculate that the snippet was generated by an older version of
I have no good guess what happened to |
Oof ... I was looking at it wrong, thanks for pointing out that this went the wrong way. According to metadata that are usually very reliable we're using mypy at this commit: That's from Aug 11, 2023, just 2 months ago. This is what the
Could it be that |
The C++ signatures in docstrings should be fixed on the binding code side: I don't how Yes, |
Thanks for the pointer. I'll relay that to the owners of the code. |
It's coming straight back at me like a boomerang:
What could we do there (in pybind11/pybind11.h)? |
What I believe it should be fixed on the If we are talking about fixing |
@sizmailov wrote:
That's not possible: the Python name is not known at compile time ( After turning this over in my mind, discarding several ideas, and asking my team mates for advice, I landed on this: It's probably best to continue the discussion there. |
make_*iterator
docmake_*iterator
doc
We should have added the test from this issue: #4100 Can we verify we did not accidentally reintroduce this problem? |
Description
Render typed iterators for
make_iterator
,make_key_iterator
,make_value_iterator
.Example:
The benchmark shows no measurable differences in runtime performance.
bench.py
The module size is increased by 8192 bytes (~0.2%):
Previous attempts to address the same issue:
#2244
#2371
Suggested changelog entry: