-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fixes issue #3801 #3807
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
Merged
Merged
Fixes issue #3801 #3807
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
10cc0e2
Fixes issue
d107a06
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 50bd80a
Fix lint error
26aa3a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] febb4f2
Fix flake8
ca68831
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ff6f41e
Fix test
6157d79
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3a5baa2
Fix clang tidy
c714d58
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cf51ccd
Fix again
749d3cc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 79cedf9
Fix test
wangxf123456 d8daf83
Add comments
wangxf123456 84fb7b4
Try fix Valgrind
wangxf123456 06e5658
Resolve comments
wangxf123456 099d1f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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 hidden or 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,26 +3,73 @@ | |
from pybind11_tests import class_sh_void_ptr_capsule as m | ||
|
||
|
||
class Valid: | ||
def __init__(self): | ||
self.capsule_generated = False | ||
|
||
def as_pybind11_tests_class_sh_void_ptr_capsule_Valid(self): # noqa: N802 | ||
self.capsule_generated = True | ||
return m.create_test_void_ptr_capsule() | ||
|
||
|
||
class NoConversion: | ||
def __init__(self): | ||
self.capsule_generated = False | ||
|
||
|
||
class NoCapsuleReturned: | ||
def __init__(self): | ||
self.capsule_generated = False | ||
|
||
def as_pybind11_tests_class_sh_void_ptr_capsule_NoCapsuleReturned( # noqa: N802 | ||
self, | ||
): | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
or
would seem either most idiomatic or most explicit. |
||
|
||
|
||
class AsAnotherObject: | ||
def __init__(self): | ||
self.capsule_generated = False | ||
|
||
def as_pybind11_tests_class_sh_void_ptr_capsule_Valid(self): # noqa: N802 | ||
self.capsule_generated = True | ||
return m.create_test_void_ptr_capsule() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ctor, caller, expected, capsule_generated", | ||
[ | ||
(m.Valid, m.get_from_valid_capsule, 101, False), | ||
(m.NoConversion, m.get_from_no_conversion_capsule, 102, False), | ||
(m.NoCapsuleReturned, m.get_from_no_capsule_returned, 103, False), | ||
(m.AsAnotherObject, m.get_from_valid_capsule, 104, True), | ||
(Valid, m.get_from_valid_capsule, 1, True), | ||
(AsAnotherObject, m.get_from_valid_capsule, 1, True), | ||
], | ||
) | ||
def test_as_void_ptr_capsule(ctor, caller, expected, capsule_generated): | ||
def test_valid_as_void_ptr_capsule_function(ctor, caller, expected, capsule_generated): | ||
obj = ctor() | ||
assert caller(obj) == expected | ||
assert obj.capsule_generated == capsule_generated | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ctor, caller, expected, capsule_generated", | ||
[ | ||
(NoConversion, m.get_from_no_conversion_capsule, 2, False), | ||
(NoCapsuleReturned, m.get_from_no_capsule_returned, 3, False), | ||
], | ||
) | ||
def test_invalid_as_void_ptr_capsule_function( | ||
ctor, caller, expected, capsule_generated | ||
): | ||
obj = ctor() | ||
with pytest.raises(TypeError): | ||
caller(obj) | ||
assert obj.capsule_generated == capsule_generated | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ctor, caller, pointer_type, capsule_generated", | ||
[ | ||
(m.AsAnotherObject, m.get_from_shared_ptr_valid_capsule, "shared_ptr", True), | ||
(m.AsAnotherObject, m.get_from_unique_ptr_valid_capsule, "unique_ptr", True), | ||
(AsAnotherObject, m.get_from_shared_ptr_valid_capsule, "shared_ptr", True), | ||
(AsAnotherObject, m.get_from_unique_ptr_valid_capsule, "unique_ptr", True), | ||
], | ||
) | ||
def test_as_void_ptr_capsule_unsupported(ctor, caller, pointer_type, capsule_generated): | ||
|
@@ -37,3 +84,15 @@ def test_type_with_getattr(): | |
obj = m.TypeWithGetattr() | ||
assert obj.get_42() == 42 | ||
assert obj.something == "GetAttr: something" | ||
|
||
|
||
def test_multiple_inheritance_getattr(): | ||
d1 = m.Derived1() | ||
assert d1.foo() == 0 | ||
assert d1.bar() == 1 | ||
assert d1.prop1 == "Base GetAttr: prop1" | ||
|
||
d2 = m.Derived2() | ||
assert d2.foo() == 0 | ||
assert d2.bar() == 2 | ||
assert d2.prop2 == "Base GetAttr: prop2" |
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.
While this is evidently fine on all platforms today, I'm afraid casting an arbitrary integer to a pointer could trigger some sanitizer error in the future. Ideas:
or