Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
11f756f5
Commit
11f756f5
authored
Sep 16, 2020
by
Henry Fredrick Schreiner
Committed by
Henry Schreiner
Sep 16, 2020
Browse files
fix: type bug intruduced in #2492
This now tests the old form too, and fixes the bug introduced.
parent
dec33c29
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
3 deletions
+12
-3
include/pybind11/pytypes.h
include/pybind11/pytypes.h
+2
-3
tests/test_class.cpp
tests/test_class.cpp
+4
-0
tests/test_class.py
tests/test_class.py
+6
-0
No files found.
include/pybind11/pytypes.h
View file @
11f756f5
...
@@ -153,7 +153,7 @@ public:
...
@@ -153,7 +153,7 @@ public:
/// Return the object's current reference count
/// Return the object's current reference count
int
ref_count
()
const
{
return
static_cast
<
int
>
(
Py_REFCNT
(
derived
().
ptr
()));
}
int
ref_count
()
const
{
return
static_cast
<
int
>
(
Py_REFCNT
(
derived
().
ptr
()));
}
PYBIND11_DEPRECATED
(
"Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()"
)
// TODO
PYBIND11_DEPRECATED("Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
handle
get_type
()
const
;
handle
get_type
()
const
;
private:
private:
...
@@ -1580,8 +1580,7 @@ template <typename D>
...
@@ -1580,8 +1580,7 @@ template <typename D>
str_attr_accessor
object_api
<
D
>::
doc
()
const
{
return
attr
(
"__doc__"
);
}
str_attr_accessor
object_api
<
D
>::
doc
()
const
{
return
attr
(
"__doc__"
);
}
template
<
typename
D
>
template
<
typename
D
>
PYBIND11_DEPRECATED
(
"Use py::type::of(h) instead of h.get_type()"
)
handle
object_api
<
D
>::
get_type
()
const
{
return
type
::
handle_of
(
derived
());
}
handle
object_api
<
D
>::
get_type
()
const
{
return
type
::
handle_of
(
*
this
);
}
template
<
typename
D
>
template
<
typename
D
>
bool
object_api
<
D
>::
rich_compare
(
object_api
const
&
other
,
int
value
)
const
{
bool
object_api
<
D
>::
rich_compare
(
object_api
const
&
other
,
int
value
)
const
{
...
...
tests/test_class.cpp
View file @
11f756f5
...
@@ -152,6 +152,10 @@ TEST_SUBMODULE(class_, m) {
...
@@ -152,6 +152,10 @@ TEST_SUBMODULE(class_, m) {
return
py
::
type
::
of
(
ob
);
return
py
::
type
::
of
(
ob
);
});
});
m
.
def
(
"get_type_classic"
,
[](
py
::
handle
h
)
{
return
h
.
get_type
();
});
m
.
def
(
"as_type"
,
[](
py
::
object
ob
)
{
m
.
def
(
"as_type"
,
[](
py
::
object
ob
)
{
auto
tp
=
py
::
type
(
ob
);
auto
tp
=
py
::
type
(
ob
);
if
(
py
::
isinstance
<
py
::
type
>
(
ob
))
if
(
py
::
isinstance
<
py
::
type
>
(
ob
))
...
...
tests/test_class.py
View file @
11f756f5
...
@@ -45,6 +45,12 @@ def test_type_of_py():
...
@@ -45,6 +45,12 @@ def test_type_of_py():
assert
m
.
get_type_of
(
int
)
==
type
assert
m
.
get_type_of
(
int
)
==
type
def
test_type_of_classic
():
assert
m
.
get_type_classic
(
1
)
==
int
assert
m
.
get_type_classic
(
m
.
DerivedClass1
())
==
m
.
DerivedClass1
assert
m
.
get_type_classic
(
int
)
==
type
def
test_type_of_py_nodelete
():
def
test_type_of_py_nodelete
():
# If the above test deleted the class, this will segfault
# If the above test deleted the class, this will segfault
assert
m
.
get_type_of
(
m
.
DerivedClass1
())
==
m
.
DerivedClass1
assert
m
.
get_type_of
(
m
.
DerivedClass1
())
==
m
.
DerivedClass1
...
...
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