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
36f0a15a
Commit
36f0a15a
authored
Feb 08, 2017
by
Dean Moldovan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deprecate handle::operator== in favor of object_api::is
parent
30d43c49
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
8 deletions
+12
-8
include/pybind11/eigen.h
+1
-1
include/pybind11/pybind11.h
+3
-3
include/pybind11/pytypes.h
+5
-1
tests/test_eval.cpp
+3
-3
No files found.
include/pybind11/eigen.h
View file @
36f0a15a
...
...
@@ -551,7 +551,7 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
object
matrix_type
=
sparse_module
.
attr
(
rowMajor
?
"csr_matrix"
:
"csc_matrix"
);
if
(
obj
.
get_type
()
!=
matrix_type
.
ptr
(
))
{
if
(
!
obj
.
get_type
().
is
(
matrix_type
))
{
try
{
obj
=
matrix_type
(
obj
);
}
catch
(
const
error_already_set
&
)
{
...
...
include/pybind11/pybind11.h
View file @
36f0a15a
...
...
@@ -278,7 +278,7 @@ protected:
chain
=
(
detail
::
function_record
*
)
rec_capsule
;
/* Never append a method to an overload chain of a parent class;
instead, hide the parent's overloads in this case */
if
(
chain
->
scope
!=
rec
->
scope
)
if
(
!
chain
->
scope
.
is
(
rec
->
scope
)
)
chain
=
nullptr
;
}
// Don't trigger for things like the default __init__, which are wrapper_descriptors that we are intentionally replacing
...
...
@@ -1274,7 +1274,7 @@ template <typename... Args> struct init {
using
Alias
=
typename
Class
::
type_alias
;
handle
cl_type
=
cl
;
cl
.
def
(
"__init__"
,
[
cl_type
](
handle
self_
,
Args
...
args
)
{
if
(
self_
.
get_type
()
==
cl_type
)
if
(
self_
.
get_type
()
.
is
(
cl_type
)
)
new
(
self_
.
cast
<
Base
*>
())
Base
(
args
...);
else
new
(
self_
.
cast
<
Alias
*>
())
Alias
(
args
...);
...
...
@@ -1708,7 +1708,7 @@ inline function get_type_overload(const void *this_ptr, const detail::type_info
Py_file_input
,
d
.
ptr
(),
d
.
ptr
());
if
(
result
==
nullptr
)
throw
error_already_set
();
if
(
(
handle
)
d
[
"self"
]
==
Py_None
)
if
(
d
[
"self"
].
is_none
()
)
return
function
();
Py_DECREF
(
result
);
#endif
...
...
include/pybind11/pytypes.h
View file @
36f0a15a
...
...
@@ -110,6 +110,8 @@ public:
PYBIND11_DEPRECATED
(
"call(...) was deprecated in favor of operator()(...)"
)
object
call
(
Args
&&
...
args
)
const
;
/// Equivalent to ``obj is other`` in Python.
bool
is
(
object_api
const
&
other
)
const
{
return
derived
().
ptr
()
==
other
.
derived
().
ptr
();
}
/// Equivalent to ``obj is None`` in Python.
bool
is_none
()
const
{
return
derived
().
ptr
()
==
Py_None
;
}
PYBIND11_DEPRECATED
(
"Use py::str(obj) instead"
)
...
...
@@ -167,10 +169,12 @@ public:
/// Return ``true`` when the `handle` wraps a valid Python object
explicit
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
/** \rst
Check that the underlying pointers are the same.
Deprecated:
Check that the underlying pointers are the same.
Equivalent to ``obj1 is obj2`` in Python.
\endrst */
PYBIND11_DEPRECATED
(
"Use obj1.is(obj2) instead"
)
bool
operator
==
(
const
handle
&
h
)
const
{
return
m_ptr
==
h
.
m_ptr
;
}
PYBIND11_DEPRECATED
(
"Use !obj1.is(obj2) instead"
)
bool
operator
!=
(
const
handle
&
h
)
const
{
return
m_ptr
!=
h
.
m_ptr
;
}
PYBIND11_DEPRECATED
(
"Use handle::operator bool() instead"
)
bool
check
()
const
{
return
m_ptr
!=
nullptr
;
}
...
...
tests/test_eval.cpp
View file @
36f0a15a
...
...
@@ -37,7 +37,7 @@ test_initializer eval([](py::module &m) {
);
auto
x
=
local
[
"x"
].
cast
<
int
>
();
return
result
==
py
::
none
()
&&
x
==
42
;
return
result
.
is_
none
()
&&
x
==
42
;
});
m
.
def
(
"test_eval"
,
[
global
]()
{
...
...
@@ -55,7 +55,7 @@ test_initializer eval([](py::module &m) {
auto
result
=
py
::
eval
<
py
::
eval_single_statement
>
(
"x = call_test()"
,
py
::
dict
(),
local
);
auto
x
=
local
[
"x"
].
cast
<
int
>
();
return
result
==
py
::
none
()
&&
x
==
42
;
return
result
.
is_
none
()
&&
x
==
42
;
});
m
.
def
(
"test_eval_file"
,
[
global
](
py
::
str
filename
)
{
...
...
@@ -66,7 +66,7 @@ test_initializer eval([](py::module &m) {
local
[
"call_test2"
]
=
py
::
cpp_function
([
&
](
int
value
)
{
val_out
=
value
;
});
auto
result
=
py
::
eval_file
(
filename
,
global
,
local
);
return
val_out
==
43
&&
result
==
py
::
none
();
return
val_out
==
43
&&
result
.
is_
none
();
});
m
.
def
(
"test_eval_failure"
,
[]()
{
...
...
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