Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
06b673a0
Unverified
Commit
06b673a0
authored
Nov 05, 2020
by
Boris Staletic
Committed by
GitHub
Nov 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow NULL value in pybind11_meta_setattro (#2629)
parent
3e4d54bc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletions
+14
-1
include/pybind11/detail/class.h
+1
-1
tests/test_methods_and_attributes.py
+13
-0
No files found.
include/pybind11/detail/class.h
View file @
06b673a0
...
@@ -129,7 +129,7 @@ extern "C" inline int pybind11_meta_setattro(PyObject* obj, PyObject* name, PyOb
...
@@ -129,7 +129,7 @@ extern "C" inline int pybind11_meta_setattro(PyObject* obj, PyObject* name, PyOb
// 2. `Type.static_prop = other_static_prop` --> setattro: replace existing `static_prop`
// 2. `Type.static_prop = other_static_prop` --> setattro: replace existing `static_prop`
// 3. `Type.regular_attribute = value` --> setattro: regular attribute assignment
// 3. `Type.regular_attribute = value` --> setattro: regular attribute assignment
const
auto
static_prop
=
(
PyObject
*
)
get_internals
().
static_property_type
;
const
auto
static_prop
=
(
PyObject
*
)
get_internals
().
static_property_type
;
const
auto
call_descr_set
=
descr
&&
PyObject_IsInstance
(
descr
,
static_prop
)
const
auto
call_descr_set
=
descr
&&
value
&&
PyObject_IsInstance
(
descr
,
static_prop
)
&&
!
PyObject_IsInstance
(
value
,
static_prop
);
&&
!
PyObject_IsInstance
(
value
,
static_prop
);
if
(
call_descr_set
)
{
if
(
call_descr_set
)
{
// Call `static_property.__set__()` instead of replacing the `static_property`.
// Call `static_property.__set__()` instead of replacing the `static_property`.
...
...
tests/test_methods_and_attributes.py
View file @
06b673a0
...
@@ -171,6 +171,19 @@ def test_static_properties():
...
@@ -171,6 +171,19 @@ def test_static_properties():
assert
m
.
TestPropertiesOverride
()
.
def_readonly
==
99
assert
m
.
TestPropertiesOverride
()
.
def_readonly
==
99
assert
m
.
TestPropertiesOverride
.
def_readonly_static
==
99
assert
m
.
TestPropertiesOverride
.
def_readonly_static
==
99
# Only static attributes can be deleted
del
m
.
TestPropertiesOverride
.
def_readonly_static
assert
(
hasattr
(
m
.
TestPropertiesOverride
,
"def_readonly_static"
)
and
m
.
TestPropertiesOverride
.
def_readonly_static
is
m
.
TestProperties
.
def_readonly_static
)
assert
"def_readonly_static"
not
in
m
.
TestPropertiesOverride
.
__dict__
properties_override
=
m
.
TestPropertiesOverride
()
with
pytest
.
raises
(
AttributeError
)
as
excinfo
:
del
properties_override
.
def_readonly
assert
"can't delete attribute"
in
str
(
excinfo
.
value
)
def
test_static_cls
():
def
test_static_cls
():
"""Static property getter and setters expect the type object as the their only argument"""
"""Static property getter and setters expect the type object as the their only argument"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment