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
bad589a4
Commit
bad589a4
authored
Sep 12, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deprecated py::base<>, added a macro for improved readability
parent
e99ebaed
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
15 deletions
+20
-15
docs/classes.rst
+5
-11
include/pybind11/attr.h
+4
-1
include/pybind11/common.h
+10
-0
include/pybind11/pytypes.h
+1
-3
No files found.
docs/classes.rst
View file @
bad589a4
...
@@ -185,10 +185,9 @@ inheritance relationship:
...
@@ -185,10 +185,9 @@ inheritance relationship:
std::string bark() const { return "woof!"; }
std::string bark() const { return "woof!"; }
};
};
There are t
hree
different ways of indicating a hierarchical relationship to
There are t
wo
different ways of indicating a hierarchical relationship to
pybind11: the first specifies the C++ base class as an extra template
pybind11: the first specifies the C++ base class as an extra template
parameter of the :class:`class_`; the second uses a special ``base`` attribute
parameter of the :class:`class_`:
passed into the constructor:
.. code-block:: cpp
.. code-block:: cpp
...
@@ -201,11 +200,6 @@ passed into the constructor:
...
@@ -201,11 +200,6 @@ passed into the constructor:
.def(py::init<const std::string &>())
.def(py::init<const std::string &>())
.def("bark", &Dog::bark);
.def("bark", &Dog::bark);
// Method 2: py::base attribute:
py::class_<Dog>(m, "Dog", py::base<Pet>() /* <- specify C++ parent type */)
.def(py::init<const std::string &>())
.def("bark", &Dog::bark);
Alternatively, we can also assign a name to the previously bound ``Pet``
Alternatively, we can also assign a name to the previously bound ``Pet``
:class:`class_` object and reference it when binding the ``Dog`` class:
:class:`class_` object and reference it when binding the ``Dog`` class:
...
@@ -215,13 +209,13 @@ Alternatively, we can also assign a name to the previously bound ``Pet``
...
@@ -215,13 +209,13 @@ Alternatively, we can also assign a name to the previously bound ``Pet``
pet.def(py::init<const std::string &>())
pet.def(py::init<const std::string &>())
.def_readwrite("name", &Pet::name);
.def_readwrite("name", &Pet::name);
// Method
3
: pass parent class_ object:
// Method
2
: pass parent class_ object:
py::class_<Dog>(m, "Dog", pet /* <- specify Python parent type */)
py::class_<Dog>(m, "Dog", pet /* <- specify Python parent type */)
.def(py::init<const std::string &>())
.def(py::init<const std::string &>())
.def("bark", &Dog::bark);
.def("bark", &Dog::bark);
Functionality-wise,
all three approaches are completely equivalent. Afterwards,
Functionality-wise,
both approaches are equivalent. Afterwards, instances will
instances will
expose fields and methods of both types:
expose fields and methods of both types:
.. code-block:: pycon
.. code-block:: pycon
...
...
include/pybind11/attr.h
View file @
bad589a4
...
@@ -33,7 +33,10 @@ struct name { const char *value; name(const char *value) : value(value) { } };
...
@@ -33,7 +33,10 @@ struct name { const char *value; name(const char *value) : value(value) { } };
struct
sibling
{
handle
value
;
sibling
(
const
handle
&
value
)
:
value
(
value
.
ptr
())
{
}
};
struct
sibling
{
handle
value
;
sibling
(
const
handle
&
value
)
:
value
(
value
.
ptr
())
{
}
};
/// Annotation indicating that a class derives from another given type
/// Annotation indicating that a class derives from another given type
template
<
typename
T
>
struct
base
{
};
template
<
typename
T
>
struct
base
{
PYBIND11_DEPRECATED
(
"base<T>() was deprecated in favor of specifying 'T' as a template argument to class_"
)
base
()
{
}
};
/// Keep patient alive while nurse lives
/// Keep patient alive while nurse lives
template
<
int
Nurse
,
int
Patient
>
struct
keep_alive
{
};
template
<
int
Nurse
,
int
Patient
>
struct
keep_alive
{
};
...
...
include/pybind11/common.h
View file @
bad589a4
...
@@ -30,6 +30,16 @@
...
@@ -30,6 +30,16 @@
# define PYBIND11_NOINLINE __attribute__ ((noinline))
# define PYBIND11_NOINLINE __attribute__ ((noinline))
#endif
#endif
#if __cplusplus > 201103L
# define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
#elif defined(__clang__)
# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
#elif defined(__GNUG__)
# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated))
#elif defined(_MSC_VER)
# define PYBIND11_DEPRECATED(reason) __declspec(deprecated)
#endif
#define PYBIND11_VERSION_MAJOR 1
#define PYBIND11_VERSION_MAJOR 1
#define PYBIND11_VERSION_MINOR 9
#define PYBIND11_VERSION_MINOR 9
#define PYBIND11_VERSION_PATCH dev0
#define PYBIND11_VERSION_PATCH dev0
...
...
include/pybind11/pytypes.h
View file @
bad589a4
...
@@ -43,9 +43,7 @@ public:
...
@@ -43,9 +43,7 @@ public:
bool
is_none
()
const
{
return
m_ptr
==
Py_None
;
}
bool
is_none
()
const
{
return
m_ptr
==
Py_None
;
}
template
<
typename
T
>
T
cast
()
const
;
template
<
typename
T
>
T
cast
()
const
;
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
#if __cplusplus > 201103L
PYBIND11_DEPRECATED
(
"call(...) was deprecated in favor of operator()(...)"
)
[[
deprecated
(
"call(...) was deprecated in favor of operator()(...)"
)]]
#endif
object
call
(
Args
&&
...
args
)
const
;
object
call
(
Args
&&
...
args
)
const
;
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
template
<
return_value_policy
policy
=
return_value_policy
::
automatic_reference
,
typename
...
Args
>
object
operator
()(
Args
&&
...
args
)
const
;
object
operator
()(
Args
&&
...
args
)
const
;
...
...
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