-
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
Experimenting: Annotated[Any, pybind11.CppType("cpp_namespace::UserType")]
#4888
Draft
rwgk
wants to merge
49
commits into
pybind:master
Choose a base branch
from
rwgk:annotated_any
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
7780fbc
Try `Annotated[Any, "cpp_namespace::UserType"]` unconditionally.
76b4a34
Add `struct handle_type_name<...>` specializations for `object`, `lis…
794d97e
Revert "Add `struct handle_type_name<...>` specializations for `objec…
2cafdab
Add `cpp_name_needs_typing_annotated()`
f6ae40b
clang-tidy compatibility
ea00323
Merge branch 'master' into annotated_any
272152e
`Annotated[Any, CppTypePybind11("cpp_namespace::UserType")]` based on…
90b3912
Merge branch 'master' into annotated_any
bb8709a
Remove `cpp_name_needs_typing_annotated()`. Preparation for bringing …
199532e
Reapply "Add `struct handle_type_name<...>` specializations for `obje…
7280380
Fix `handle_type_name<anyset>` as suggested by @sizmailov:
70a510c
Adjust test_numpy_dtypes test_signature to new behavior.
ace70b0
Render `anyset` as `set | frozenset` as suggested by @sizmailov:
7c8991a
Use `Union[set, frozenset]` for internal consistency.
63a4881
Add missing `handle_type_name<slice>` specialization (discovered only…
3c20944
Add missing `handle_type_name<>` specializations for `bytearray`, `me…
74817b7
Add missing `handle_type_name<module_>`.
6a3a954
Add missing `handle_type_name<dtype>`.
169b0e5
Add test returning `py::exception<void>` (fails at runtime).
acfd646
Merge branch 'master' into annotated_any
9548fa5
Merge branch 'master' into annotated_any
0b98433
Remove `CppTypePybind11()` wrapping for now.
781304e
Add test_cases_for_stubgen
61ee34e
Pull in `Annotated[list[int], FixedSize(2)]` from test_stl
1104076
Add `Annotated[Any, "..."]` wrapping in `type_info_description()`
e5f210e
Rename `user_type` to `UserType`
d1694d9
Use locally defined bindings to avoid dependency on test_stl.
1b4fa71
Unmodified copy of https://github.com/python/mypy/blob/c6cb3c6282003d…
644d150
Minimal changes to make the basics code build.
1fa0065
pre-commit clang-format, NO manual changes.
69dac46
Add `m.basics` tests in ntest_cases_for_stubgen.py
1a2e8a6
C++11 compatibility.
79f6bdc
Replace `.stl_binders.` with `.cases_for_stubgen.`
2376f6e
Use py::handle instead of py::object to avoid clang-tidy errors.
542438f
Merge branch 'master' into annotated_any
bdbb10d
Add some deeply nested test cases.
429a1f8
Make test_cases_for_stubgen.py much more compact, and the `pytest -v`…
2b2ffeb
Introduce `detail::annotated_any()` helper.
65661fe
Change `detail::annotated_any()` to produce `pybind11.CppType(...)`
6b771d5
Merge branch 'master' into annotated_any
813660c
Change `annotated_any()` to `quote_cpp_type_name()`
66ee131
Test changes to adjust to previous commit (Change `annotated_any()` t…
d14d91e
Remove `handle_type_name` default implementation, add explicit specia…
1e6bea2
Merge branch 'master' into annotated_any
bf6077a
style: pre-commit fixes
pre-commit-ci[bot] b02767d
Merge branch 'master' into annotated_any
67c41cc
Merge branch 'master' into annotated_any
8c5bb07
Merge branch 'master' into annotated_any
d57ed51
Adjustments related to pybind/pybind11#4985
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Strictly speaking, we should always wrap C++ types with
Annotated
at this point.Being a top-level non-template type is not enough to assume 1-to-1 C++-Python type name correspondence, although it is the case for (some) built-in types.
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.
Adding the following to
cast.h
allows us to remove the above condition without turning all tests red.The only two failures probably indicate the error in tests themselves:
Pytest errors
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.
Sorry I didn't point out before, I got the same result already, it's in a commit here: 76b4a34
The only remaining errors are related to numpy
NestedStruct
. I tried to pin-point where the%
originates, but I gave up after looking for ~5 minutes, reverted the commit, and then tried thecpp_name_needs_typing_annotated()
heuristic instead to see how far we get with that.I agree what you suggest here is best, but someone needs to figure out how to deal with the failing test, and then we have to decide if we need to roll out the behavior change in stages, maybe opt-in first in one release, then opt-out in the next.
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.
Oh, right. You already tried that. I should have noticed.
I think we should apply the following diff to tests.
NestedStruct
doesn't have a descriptive python counterpart, theCppTypePybind11("NestedType")
is the best we can do.anyset
in python.This should resolve the troubles with broken tests.
diff
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.
Nice, thanks! I didn't know / wasn't sure before. I'm glad I gave up before, finding out the hard way. :-)
Of course! :-) Thanks for catching that as well, I was just going through with rushed lawnmower mentality.
Please take another look, the
cpp_name_needs_typing_annotated()
heuristic is gone, all tests pass (locally at least).