Classes | Namespaces | Macros | Typedefs | Functions
pytypes.h File Reference
#include "detail/common.h"
#include "buffer_info.h"
#include <assert.h>
#include <cstddef>
#include <exception>
#include <frameobject.h>
#include <iterator>
#include <memory>
#include <string>
#include <type_traits>
#include <typeinfo>
#include <utility>
Include dependency graph for pytypes.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  accessor< Policy >
 
class  anyset
 
class  args
 
class  args_proxy
 
struct  arrow_proxy< T >
 Quick proxy class needed to implement operator-> for iterators which can't return pointers. More...
 
class  bool_
 
struct  object::borrowed_t
 
class  buffer
 
class  bytearray
 
class  bytes
 
class  capsule
 
class  dict
 
class  dict_readonly
 Python's dictionary protocol permits this to be a forward iterator. More...
 
class  ellipsis
 
class  error_already_set
 
struct  error_fetch_and_normalize
 
class  float_
 
class  frozenset
 
class  function
 
struct  generic_item
 
class  generic_iterator< Policy >
 STL iterator template used for tuple, list, sequence and dict. More...
 
class  handle
 
class  int_
 
class  iterable
 
class  iterator
 
class  kwargs
 
class  kwargs_proxy
 
class  list
 
struct  list_item
 
class  memoryview
 
class  none
 
struct  obj_attr
 
class  object
 
class  object_api< Derived >
 
class  pyobject_tag
 Tag and check to identify a class which implements the Python object API. More...
 
class  sequence
 
class  sequence_fast_readonly
 Lightweight iterator policy using just a simple pointer: see PySequence_Fast_ITEMS More...
 
struct  sequence_item
 
class  sequence_slow_readwrite
 Full read and write access using the sequence protocol: see detail::sequence_accessor More...
 
class  set
 
class  simple_collector< policy >
 
class  slice
 
class  staticmethod
 
struct  object::stolen_t
 
class  str
 
struct  str_attr
 
class  tuple
 
struct  tuple_item
 
class  type
 
class  unpacking_collector< policy >
 Helper class which collects positional, keyword, * and ** arguments for a Python function call. More...
 
class  weakref
 

Namespaces

 accessor_policies
 
 literals
 

Macros

#define PYBIND11_HANDLE_REF_DEBUG
 
#define PYBIND11_INPLACE_OP(iop)   object iop(object_api const &other) { return operator=(handle::iop(other)); }
 
#define PYBIND11_MATH_OPERATOR_BINARY(op, fn)
 
#define PYBIND11_MATH_OPERATOR_BINARY_INPLACE(iop, fn)
 
#define PYBIND11_MATH_OPERATOR_UNARY(op, fn)
 
#define PYBIND11_OBJECT(Name, Parent, CheckFun)
 
#define PYBIND11_OBJECT_CHECK_FAILED(Name, o_ptr)
 
#define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun)
 
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun)
 
#define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun)
 
#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun)
 
#define PYBIND11_STR_CHECK_FUN   PyUnicode_Check
 

Typedefs

using dict_iterator = generic_iterator< iterator_policies::dict_readonly >
 
template<typename T >
using is_ds_unpacking = std::is_same< kwargs_proxy, T >
 
template<typename T >
using is_keyword = std::is_base_of< arg, T >
 Python argument categories (using PEP 448 terms) More...
 
template<typename T >
using is_keyword_or_ds = satisfies_any_of< T, is_keyword, is_ds_unpacking >
 
template<typename T >
using is_positional = satisfies_none_of< T, is_keyword, is_s_unpacking, is_ds_unpacking >
 
template<typename T >
using is_pyobj_ptr_or_nullptr_t = detail::any_of< std::is_same< T, PyObject * >, std::is_same< T, PyObject *const >, std::is_same< T, std::nullptr_t > >
 
template<typename T >
using is_pyobject = std::is_base_of< pyobject_tag, remove_reference_t< T > >
 
template<typename T >
using is_s_unpacking = std::is_same< args_proxy, T >
 
using item_accessor = accessor< accessor_policies::generic_item >
 
using list_accessor = accessor< accessor_policies::list_item >
 
using list_iterator = generic_iterator< iterator_policies::sequence_fast_readonly >
 
using obj_attr_accessor = accessor< accessor_policies::obj_attr >
 
using sequence_accessor = accessor< accessor_policies::sequence_item >
 
using sequence_iterator = generic_iterator< iterator_policies::sequence_slow_readwrite >
 
using str_attr_accessor = accessor< accessor_policies::str_attr >
 
using tuple_accessor = accessor< accessor_policies::tuple_item >
 
using tuple_iterator = generic_iterator< iterator_policies::sequence_fast_readonly >
 

Functions

template<typename... Args>
constexpr bool args_are_all_keyword_or_ds ()
 
template<typename Unsigned >
Unsigned as_unsigned (PyObject *o)
 
void delattr (handle obj, const char *name)
 
void delattr (handle obj, handle name)
 
PyObject * dict_getitem (PyObject *v, PyObject *key)
 
PyObject * dict_getitemstring (PyObject *v, const char *key)
 
PyObject * dict_getitemstringref (PyObject *v, const char *key)
 
std::string error_string ()
 
handle get_function (handle value)
 
object getattr (handle obj, const char *name)
 
object getattr (handle obj, const char *name, handle default_)
 
object getattr (handle obj, handle name)
 
object getattr (handle obj, handle name, handle default_)
 
bool hasattr (handle obj, const char *name)
 
bool hasattr (handle obj, handle name)
 
ssize_t hash (handle obj)
 
template<typename T , detail::enable_if_t< std::is_base_of< object, T >::value, int > = 0>
bool isinstance (handle obj)
 
bool isinstance (handle obj, handle type)
 
template<>
bool isinstance< handle > (handle)=delete
 
template<>
bool isinstance< object > (handle obj)
 
bool isinstance_generic (handle obj, const std::type_info &tp)
 
iterator iter (handle obj)
 
size_t len (handle h)
 Get the length of a Python object. More...
 
size_t len_hint (handle h)
 
const char * obj_class_name (PyObject *obj)
 
handle object_or_cast (PyObject *ptr)
 
template<typename T , enable_if_t<!is_pyobject< T >::value, int > = 0>
object object_or_cast (T &&o)
 
template<typename T , enable_if_t< is_pyobject< T >::value, int > = 0>
auto object_or_cast (T &&o) -> decltype(std::forward< T >(o))
 
str literals::operator""_s (const char *s, size_t size)
 
bool PyEllipsis_Check (PyObject *o)
 
bool PyIterable_Check (PyObject *obj)
 
bool PyNone_Check (PyObject *o)
 
bool PyStaticMethod_Check (PyObject *o)
 
void raise_from (error_already_set &err, PyObject *type, const char *message)
 
void raise_from (PyObject *type, const char *message)
 
template<typename T >
T reinterpret_borrow (handle h)
 
template<typename T >
T reinterpret_steal (handle h)
 
str repr (handle h)
 
void set_error (const handle &type, const char *message)
 
void set_error (const handle &type, const handle &value)
 
void setattr (handle obj, const char *name, handle value)
 
void setattr (handle obj, handle name, handle value)
 

Macro Definition Documentation

◆ PYBIND11_HANDLE_REF_DEBUG

#define PYBIND11_HANDLE_REF_DEBUG

Definition at line 212 of file pytypes.h.

◆ PYBIND11_INPLACE_OP

#define PYBIND11_INPLACE_OP (   iop)    object iop(object_api const &other) { return operator=(handle::iop(other)); }

Definition at line 414 of file pytypes.h.

◆ PYBIND11_MATH_OPERATOR_BINARY

#define PYBIND11_MATH_OPERATOR_BINARY (   op,
  fn 
)
Value:
template <typename D> \
object object_api<D>::op(object_api const &other) const { \
object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}

Definition at line 2560 of file pytypes.h.

◆ PYBIND11_MATH_OPERATOR_BINARY_INPLACE

#define PYBIND11_MATH_OPERATOR_BINARY_INPLACE (   iop,
  fn 
)
Value:
template <typename D> \
object object_api<D>::iop(object_api const &other) { \
object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}

Definition at line 2569 of file pytypes.h.

◆ PYBIND11_MATH_OPERATOR_UNARY

#define PYBIND11_MATH_OPERATOR_UNARY (   op,
  fn 
)
Value:
template <typename D> \
object object_api<D>::op() const { \
object result = reinterpret_steal<object>(fn(derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}

Definition at line 2551 of file pytypes.h.

◆ PYBIND11_OBJECT

#define PYBIND11_OBJECT (   Name,
  Parent,
  CheckFun 
)
Value:
PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
/* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(const object &o) : Parent(o) { \
if (m_ptr && !check_(m_ptr)) \
throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
} \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(object &&o) : Parent(std::move(o)) { \
if (m_ptr && !check_(m_ptr)) \
throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
}

Definition at line 1431 of file pytypes.h.

◆ PYBIND11_OBJECT_CHECK_FAILED

#define PYBIND11_OBJECT_CHECK_FAILED (   Name,
  o_ptr 
)
Value:
::pybind11::type_error("Object of type '" \
+ "' is not an instance of '" #Name "'")

Definition at line 1426 of file pytypes.h.

◆ PYBIND11_OBJECT_COMMON

#define PYBIND11_OBJECT_COMMON (   Name,
  Parent,
  CheckFun 
)
Value:
public: \
PYBIND11_DEPRECATED("Use reinterpret_borrow<" #Name ">() or reinterpret_steal<" #Name ">()") \
Name(handle h, bool is_borrowed) \
: Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) {} \
Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) {} \
Name(handle h, stolen_t) : Parent(h, stolen_t{}) {} \
PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \
bool check() const { return m_ptr != nullptr && (CheckFun(m_ptr) != 0); } \
static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \
template <typename Policy_> /* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) {}

Definition at line 1394 of file pytypes.h.

◆ PYBIND11_OBJECT_CVT

#define PYBIND11_OBJECT_CVT (   Name,
  Parent,
  CheckFun,
  ConvertFun 
)
Value:
PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
/* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(const object &o) \
: Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
if (!m_ptr) \
throw ::pybind11::error_already_set(); \
} \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(object &&o) : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
if (!m_ptr) \
throw ::pybind11::error_already_set(); \
}

Definition at line 1407 of file pytypes.h.

◆ PYBIND11_OBJECT_CVT_DEFAULT

#define PYBIND11_OBJECT_CVT_DEFAULT (   Name,
  Parent,
  CheckFun,
  ConvertFun 
)
Value:
PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \
Name() = default;

Definition at line 1422 of file pytypes.h.

◆ PYBIND11_OBJECT_DEFAULT

#define PYBIND11_OBJECT_DEFAULT (   Name,
  Parent,
  CheckFun 
)
Value:
PYBIND11_OBJECT(Name, Parent, CheckFun) \
Name() = default;

Definition at line 1445 of file pytypes.h.

◆ PYBIND11_STR_CHECK_FUN

#define PYBIND11_STR_CHECK_FUN   PyUnicode_Check

Definition at line 1354 of file pytypes.h.

Typedef Documentation

◆ dict_iterator

using dict_iterator = generic_iterator<iterator_policies::dict_readonly>

Definition at line 1333 of file pytypes.h.

◆ is_ds_unpacking

template<typename T >
using is_ds_unpacking = std::is_same<kwargs_proxy, T>

Definition at line 1376 of file pytypes.h.

◆ is_keyword

template<typename T >
using is_keyword = std::is_base_of<arg, T>

Python argument categories (using PEP 448 terms)

Definition at line 1372 of file pytypes.h.

◆ is_keyword_or_ds

template<typename T >
using is_keyword_or_ds = satisfies_any_of<T, is_keyword, is_ds_unpacking>

Definition at line 1380 of file pytypes.h.

◆ is_positional

Definition at line 1378 of file pytypes.h.

◆ is_pyobj_ptr_or_nullptr_t

template<typename T >
using is_pyobj_ptr_or_nullptr_t = detail::any_of<std::is_same<T, PyObject *>, std::is_same<T, PyObject *const>, std::is_same<T, std::nullptr_t> >

Definition at line 207 of file pytypes.h.

◆ is_pyobject

template<typename T >
using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T> >

Definition at line 73 of file pytypes.h.

◆ is_s_unpacking

template<typename T >
using is_s_unpacking = std::is_same<args_proxy, T>

Definition at line 1374 of file pytypes.h.

◆ item_accessor

using item_accessor = accessor<accessor_policies::generic_item>

Definition at line 65 of file pytypes.h.

◆ list_accessor

using list_accessor = accessor<accessor_policies::list_item>

Definition at line 67 of file pytypes.h.

◆ list_iterator

using list_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>

Definition at line 1326 of file pytypes.h.

◆ obj_attr_accessor

using obj_attr_accessor = accessor<accessor_policies::obj_attr>

Definition at line 63 of file pytypes.h.

◆ sequence_accessor

using sequence_accessor = accessor<accessor_policies::sequence_item>

Definition at line 66 of file pytypes.h.

◆ sequence_iterator

using sequence_iterator = generic_iterator<iterator_policies::sequence_slow_readwrite>

Definition at line 1332 of file pytypes.h.

◆ str_attr_accessor

using str_attr_accessor = accessor<accessor_policies::str_attr>

Definition at line 64 of file pytypes.h.

◆ tuple_accessor

using tuple_accessor = accessor<accessor_policies::tuple_item>

Definition at line 68 of file pytypes.h.

◆ tuple_iterator

using tuple_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>

Definition at line 1325 of file pytypes.h.

Function Documentation

◆ dict_getitem()

PyObject* dict_getitem ( PyObject *  v,
PyObject *  key 
)
inline

Definition at line 975 of file pytypes.h.

◆ dict_getitemstring()

PyObject* dict_getitemstring ( PyObject *  v,
const char *  key 
)
inline

Definition at line 960 of file pytypes.h.

◆ dict_getitemstringref()

PyObject* dict_getitemstringref ( PyObject *  v,
const char *  key 
)
inline

Definition at line 983 of file pytypes.h.

◆ error_string()

std::string error_string ( )
inline

Definition at line 729 of file pytypes.h.

◆ get_function()

handle get_function ( handle  value)
inline

Definition at line 945 of file pytypes.h.

◆ isinstance< handle >()

template<>
bool isinstance< handle > ( handle  )
inlinedelete

◆ isinstance< object >()

template<>
bool isinstance< object > ( handle  obj)
inline

Definition at line 854 of file pytypes.h.

◆ isinstance_generic()

bool isinstance_generic ( handle  obj,
const std::type_info &  tp 
)

Definition at line 495 of file type_caster_base.h.

◆ obj_class_name()

const char* obj_class_name ( PyObject *  obj)
inline

Definition at line 487 of file pytypes.h.

◆ object_or_cast() [1/3]

handle object_or_cast ( PyObject *  ptr)
inline

Definition at line 1011 of file pytypes.h.

◆ object_or_cast() [2/3]

template<typename T , enable_if_t<!is_pyobject< T >::value, int > = 0>
object object_or_cast ( T &&  o)

Definition at line 1313 of file cast.h.

◆ object_or_cast() [3/3]

template<typename T , enable_if_t< is_pyobject< T >::value, int > = 0>
auto object_or_cast ( T &&  o) -> decltype(std::forward<T>(o))

Definition at line 1004 of file pytypes.h.

◆ PyEllipsis_Check()

bool PyEllipsis_Check ( PyObject *  o)
inline

Definition at line 1346 of file pytypes.h.

◆ PyIterable_Check()

bool PyIterable_Check ( PyObject *  obj)
inline

Definition at line 1335 of file pytypes.h.

◆ PyNone_Check()

bool PyNone_Check ( PyObject *  o)
inline

Definition at line 1345 of file pytypes.h.

◆ PyStaticMethod_Check()

bool PyStaticMethod_Check ( PyObject *  o)
inline

Definition at line 1357 of file pytypes.h.

◆ raise_from() [1/2]

void raise_from ( error_already_set err,
PyObject *  type,
const char *  message 
)
inline

Sets the current Python error indicator with the chosen error, performing a 'raise from' from the error contained in error_already_set to indicate that the chosen error was caused by the original error.

Definition at line 826 of file pytypes.h.

◆ raise_from() [2/2]

void raise_from ( PyObject *  type,
const char *  message 
)
inline

Replaces the current Python error indicator with the chosen error, performing a 'raise from' to indicate that the chosen error was caused by the original error.

Definition at line 797 of file pytypes.h.

◆ reinterpret_borrow()

template<typename T >
T reinterpret_borrow ( handle  h)

\rst Declare that a handle or PyObject * is a certain type and borrow the reference. The target type T must be object or one of its derived classes. The function doesn't do any conversions or checks. It's up to the user to make sure that the target type is correct.

.. code-block:: cpp

PyObject *p = PyList_GetItem(obj, index);
py::object o = reinterpret_borrow<py::object>(p);

or py::tuple t = reinterpret_borrow<py::tuple>(p); // <– p must be already be a tuple \endrst

Definition at line 467 of file pytypes.h.

◆ reinterpret_steal()

template<typename T >
T reinterpret_steal ( handle  h)

\rst Like reinterpret_borrow, but steals the reference.

.. code-block:: cpp

PyObject *p = PyObject_Str(obj); py::str s = reinterpret_steal<py::str>(p); // <– p must be already be a str \endrst

Definition at line 480 of file pytypes.h.

◆ set_error() [1/2]

void set_error ( const handle type,
const char *  message 
)
inline

Definition at line 346 of file pytypes.h.

◆ set_error() [2/2]

void set_error ( const handle type,
const handle value 
)
inline

Definition at line 350 of file pytypes.h.

PYBIND11_OBJECT_COMMON
#define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun)
Definition: pytypes.h:1394
PYBIND11_OBJECT
#define PYBIND11_OBJECT(Name, Parent, CheckFun)
Definition: pytypes.h:1431
error_already_set
Definition: pytypes.h:739
fn
static double fn[10]
Definition: fresnl.c:103
object_api
Definition: pytypes.h:80
PYBIND11_OBJECT_CVT
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun)
Definition: pytypes.h:1407
h
const double h
Definition: testSimpleHelicopter.cpp:19
result
Values result
Definition: OdometryOptimize.cpp:8
object
Definition: pytypes.h:364
get_fully_qualified_tp_name
std::string get_fully_qualified_tp_name(PyTypeObject *type)
Definition: class.h:28
handle
Definition: pytypes.h:226
conf.release
release
Definition: gtsam/3rdparty/GeographicLib/python/doc/conf.py:69
check
void check(bool b, bool ref)
Definition: fastmath.cpp:12
PYBIND11_OBJECT_CHECK_FAILED
#define PYBIND11_OBJECT_CHECK_FAILED(Name, o_ptr)
Definition: pytypes.h:1426
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
move
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1243
std
Definition: BFloat16.h:88
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:09:50