pytypes.h
Go to the documentation of this file.
1 /*
2  pybind11/pytypes.h: Convenience wrapper classes for basic Python types
3 
4  Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5 
6  All rights reserved. Use of this source code is governed by a
7  BSD-style license that can be found in the LICENSE file.
8 */
9 
10 #pragma once
11 
12 #include "detail/common.h"
13 #include "buffer_info.h"
14 
15 #include <assert.h>
16 #include <cstddef>
17 #include <exception>
18 #include <frameobject.h>
19 #include <iterator>
20 #include <memory>
21 #include <string>
22 #include <type_traits>
23 #include <typeinfo>
24 #include <utility>
25 
26 #if defined(PYBIND11_HAS_OPTIONAL)
27 # include <optional>
28 #endif
29 
30 #ifdef PYBIND11_HAS_STRING_VIEW
31 # include <string_view>
32 #endif
33 
35 
37 
38 /* A few forward declarations */
39 class handle;
40 class object;
41 class str;
42 class iterator;
43 class type;
44 struct arg;
45 struct arg_v;
46 
48 class args_proxy;
49 bool isinstance_generic(handle obj, const std::type_info &tp);
50 
51 // Accessor forward declarations
52 template <typename Policy>
53 class accessor;
54 namespace accessor_policies {
55 struct obj_attr;
56 struct str_attr;
57 struct generic_item;
58 struct sequence_item;
59 struct list_item;
60 struct tuple_item;
61 } // namespace accessor_policies
62 // PLEASE KEEP handle_type_name SPECIALIZATIONS IN SYNC.
69 
71 class pyobject_tag {};
72 template <typename T>
73 using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T>>;
74 
79 template <typename Derived>
80 class object_api : public pyobject_tag {
81  const Derived &derived() const { return static_cast<const Derived &>(*this); }
82 
83 public:
88  iterator begin() const;
90  iterator end() const;
91 
100  item_accessor operator[](object &&key) const;
102  item_accessor operator[](const char *key) const;
103 
112  obj_attr_accessor attr(object &&key) const;
114  str_attr_accessor attr(const char *key) const;
115 
122  args_proxy operator*() const;
123 
125  template <typename T>
126  bool contains(T &&item) const;
127 
139  typename... Args>
140  object operator()(Args &&...args) const;
142  typename... Args>
143  PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)")
144  object call(Args &&...args) const;
145 
147  bool is(object_api const &other) const { return derived().ptr() == other.derived().ptr(); }
149  bool is_none() const { return derived().ptr() == Py_None; }
151  bool equal(object_api const &other) const { return rich_compare(other, Py_EQ); }
152  bool not_equal(object_api const &other) const { return rich_compare(other, Py_NE); }
153  bool operator<(object_api const &other) const { return rich_compare(other, Py_LT); }
154  bool operator<=(object_api const &other) const { return rich_compare(other, Py_LE); }
155  bool operator>(object_api const &other) const { return rich_compare(other, Py_GT); }
156  bool operator>=(object_api const &other) const { return rich_compare(other, Py_GE); }
157 
158  object operator-() const;
159  object operator~() const;
160  object operator+(object_api const &other) const;
161  object operator+=(object_api const &other);
162  object operator-(object_api const &other) const;
163  object operator-=(object_api const &other);
164  object operator*(object_api const &other) const;
165  object operator*=(object_api const &other);
166  object operator/(object_api const &other) const;
167  object operator/=(object_api const &other);
168  object operator|(object_api const &other) const;
169  object operator|=(object_api const &other);
170  object operator&(object_api const &other) const;
171  object operator&=(object_api const &other);
172  object operator^(object_api const &other) const;
173  object operator^=(object_api const &other);
174  object operator<<(object_api const &other) const;
175  object operator<<=(object_api const &other);
176  object operator>>(object_api const &other) const;
177  object operator>>=(object_api const &other);
178 
179  PYBIND11_DEPRECATED("Use py::str(obj) instead")
180  pybind11::str str() const;
181 
183  str_attr_accessor doc() const;
184 
186  ssize_t ref_count() const {
187 #ifdef PYPY_VERSION
188  // PyPy uses the top few bits for REFCNT_FROM_PYPY & REFCNT_FROM_PYPY_LIGHT
189  // Following pybind11 2.12.1 and older behavior and removing this part
190  return static_cast<ssize_t>(static_cast<int>(Py_REFCNT(derived().ptr())));
191 #else
192  return Py_REFCNT(derived().ptr());
193 #endif
194  }
195 
196  // TODO PYBIND11_DEPRECATED(
197  // "Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
198  handle get_type() const;
199 
200 private:
201  bool rich_compare(object_api const &other, int value) const;
202 };
203 
204 template <typename T>
205 using is_pyobj_ptr_or_nullptr_t = detail::any_of<std::is_same<T, PyObject *>,
206  std::is_same<T, PyObject *const>,
207  std::is_same<T, std::nullptr_t>>;
208 
210 
211 #if !defined(PYBIND11_HANDLE_REF_DEBUG) && !defined(NDEBUG)
212 # define PYBIND11_HANDLE_REF_DEBUG
213 #endif
214 
226 class handle : public detail::object_api<handle> {
227 public:
229  handle() = default;
230 
233  template <typename T,
235  // NOLINTNEXTLINE(google-explicit-constructor)
237 
239  template <
240  typename T,
241  detail::enable_if_t<detail::all_of<detail::none_of<std::is_base_of<handle, T>,
242  detail::is_pyobj_ptr_or_nullptr_t<T>>,
243  std::is_convertible<T, PyObject *>>::value,
244  int>
245  = 0>
246  // NOLINTNEXTLINE(google-explicit-constructor)
247  handle(T &obj) : m_ptr(obj) {}
248 
250  PyObject *ptr() const { return m_ptr; }
251  PyObject *&ptr() { return m_ptr; }
252 
258  const handle &inc_ref() const & {
259 #ifdef PYBIND11_HANDLE_REF_DEBUG
260  inc_ref_counter(1);
261 #endif
262 #ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
263  if (m_ptr != nullptr && !PyGILState_Check()) {
264  throw_gilstate_error("pybind11::handle::inc_ref()");
265  }
266 #endif
267  Py_XINCREF(m_ptr);
268  return *this;
269  }
270 
276  const handle &dec_ref() const & {
277 #ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
278  if (m_ptr != nullptr && !PyGILState_Check()) {
279  throw_gilstate_error("pybind11::handle::dec_ref()");
280  }
281 #endif
282  Py_XDECREF(m_ptr);
283  return *this;
284  }
285 
290  template <typename T>
291  T cast() const;
293  explicit operator bool() const { return m_ptr != nullptr; }
298  PYBIND11_DEPRECATED("Use obj1.is(obj2) instead")
299  bool operator==(const handle &h) const { return m_ptr == h.m_ptr; }
300  PYBIND11_DEPRECATED("Use !obj1.is(obj2) instead")
301  bool operator!=(const handle &h) const { return m_ptr != h.m_ptr; }
302  PYBIND11_DEPRECATED("Use handle::operator bool() instead")
303  bool check() const { return m_ptr != nullptr; }
304 
305 protected:
306  PyObject *m_ptr = nullptr;
307 
308 private:
309 #ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
310  void throw_gilstate_error(const std::string &function_name) const {
311  fprintf(
312  stderr,
313  "%s is being called while the GIL is either not held or invalid. Please see "
314  "https://pybind11.readthedocs.io/en/stable/advanced/"
315  "misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n"
316  "If you are convinced there is no bug in your code, you can #define "
317  "PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF "
318  "to disable this check. In that case you have to ensure this #define is consistently "
319  "used for all translation units linked into a given pybind11 extension, otherwise "
320  "there will be ODR violations.",
321  function_name.c_str());
322  if (Py_TYPE(m_ptr)->tp_name != nullptr) {
323  fprintf(stderr,
324  " The failing %s call was triggered on a %s object.",
325  function_name.c_str(),
326  Py_TYPE(m_ptr)->tp_name);
327  }
328  fprintf(stderr, "\n");
329  fflush(stderr);
330  throw std::runtime_error(function_name + " PyGILState_Check() failure.");
331  }
332 #endif
333 
334 #ifdef PYBIND11_HANDLE_REF_DEBUG
336  thread_local std::size_t counter = 0;
337  counter += add;
338  return counter;
339  }
340 
341 public:
343 #endif
344 };
345 
346 inline void set_error(const handle &type, const char *message) {
347  PyErr_SetString(type.ptr(), message);
348 }
349 
350 inline void set_error(const handle &type, const handle &value) {
351  PyErr_SetObject(type.ptr(), value.ptr());
352 }
353 
364 class object : public handle {
365 public:
366  object() = default;
367  PYBIND11_DEPRECATED("Use reinterpret_borrow<object>() or reinterpret_steal<object>()")
368  object(handle h, bool is_borrowed) : handle(h) {
369  if (is_borrowed) {
371  }
372  }
374  object(const object &o) : handle(o) { inc_ref(); }
376  object(object &&other) noexcept : handle(other) { other.m_ptr = nullptr; }
378  ~object() { dec_ref(); }
379 
386  PyObject *tmp = m_ptr;
387  m_ptr = nullptr;
388  return handle(tmp);
389  }
390 
391  object &operator=(const object &other) {
392  // Skip inc_ref and dec_ref if both objects are the same
393  if (!this->is(other)) {
394  other.inc_ref();
395  // Use temporary variable to ensure `*this` remains valid while
396  // `Py_XDECREF` executes, in case `*this` is accessible from Python.
397  handle temp(m_ptr);
398  m_ptr = other.m_ptr;
399  temp.dec_ref();
400  }
401  return *this;
402  }
403 
404  object &operator=(object &&other) noexcept {
405  if (this != &other) {
406  handle temp(m_ptr);
407  m_ptr = other.m_ptr;
408  other.m_ptr = nullptr;
409  temp.dec_ref();
410  }
411  return *this;
412  }
413 
414 #define PYBIND11_INPLACE_OP(iop) \
415  object iop(object_api const &other) { return operator=(handle::iop(other)); }
416 
417  PYBIND11_INPLACE_OP(operator+=)
418  PYBIND11_INPLACE_OP(operator-=)
419  PYBIND11_INPLACE_OP(operator*=)
420  PYBIND11_INPLACE_OP(operator/=)
421  PYBIND11_INPLACE_OP(operator|=)
422  PYBIND11_INPLACE_OP(operator&=)
423  PYBIND11_INPLACE_OP(operator^=)
424  PYBIND11_INPLACE_OP(operator<<=)
425  PYBIND11_INPLACE_OP(operator>>=)
426 #undef PYBIND11_INPLACE_OP
427 
428  // Calling cast() on an object lvalue just copies (via handle::cast)
429  template <typename T>
430  T cast() const &;
431  // Calling on an object rvalue does a move, if needed and/or possible
432  template <typename T>
433  T cast() &&;
434 
435 protected:
436  // Tags for choosing constructors from raw PyObject *
437  struct borrowed_t {};
438  struct stolen_t {};
439 
441  template <typename T>
442  friend T reinterpret_borrow(handle);
443  template <typename T>
444  friend T reinterpret_steal(handle);
446 
447 public:
448  // Only accessible from derived classes and the reinterpret_* functions
451 };
452 
466 template <typename T>
468  return {h, object::borrowed_t{}};
469 }
470 
479 template <typename T>
481  return {h, object::stolen_t{}};
482 }
483 
485 
486 // Equivalent to obj.__class__.__name__ (or obj.__name__ if obj is a class).
487 inline const char *obj_class_name(PyObject *obj) {
488  if (PyType_Check(obj)) {
489  return reinterpret_cast<PyTypeObject *>(obj)->tp_name;
490  }
491  return Py_TYPE(obj)->tp_name;
492 }
493 
494 std::string error_string();
495 
496 // The code in this struct is very unusual, to minimize the chances of
497 // masking bugs (elsewhere) by errors during the error handling (here).
498 // This is meant to be a lifeline for troubleshooting long-running processes
499 // that crash under conditions that are virtually impossible to reproduce.
500 // Low-level implementation alternatives are preferred to higher-level ones
501 // that might raise cascading exceptions. Last-ditch-kind-of attempts are made
502 // to report as much of the original error as possible, even if there are
503 // secondary issues obtaining some of the details.
505  // This comment only applies to Python <= 3.11:
506  // Immediate normalization is long-established behavior (starting with
507  // https://github.com/pybind/pybind11/commit/135ba8deafb8bf64a15b24d1513899eb600e2011
508  // from Sep 2016) and safest. Normalization could be deferred, but this could mask
509  // errors elsewhere, the performance gain is very minor in typical situations
510  // (usually the dominant bottleneck is EH unwinding), and the implementation here
511  // would be more complex.
512  // Starting with Python 3.12, PyErr_Fetch() normalizes exceptions immediately.
513  // Any errors during normalization are tracked under __notes__.
514  explicit error_fetch_and_normalize(const char *called) {
515  PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
516  if (!m_type) {
517  pybind11_fail("Internal error: " + std::string(called)
518  + " called while "
519  "Python error indicator not set.");
520  }
521  const char *exc_type_name_orig = detail::obj_class_name(m_type.ptr());
522  if (exc_type_name_orig == nullptr) {
523  pybind11_fail("Internal error: " + std::string(called)
524  + " failed to obtain the name "
525  "of the original active exception type.");
526  }
527  m_lazy_error_string = exc_type_name_orig;
528 #if PY_VERSION_HEX >= 0x030C0000
529  // The presence of __notes__ is likely due to exception normalization
530  // errors, although that is not necessarily true, therefore insert a
531  // hint only:
532  if (PyObject_HasAttrString(m_value.ptr(), "__notes__")) {
533  m_lazy_error_string += "[WITH __notes__]";
534  }
535 #else
536  // PyErr_NormalizeException() may change the exception type if there are cascading
537  // failures. This can potentially be extremely confusing.
538  PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
539  if (m_type.ptr() == nullptr) {
540  pybind11_fail("Internal error: " + std::string(called)
541  + " failed to normalize the "
542  "active exception.");
543  }
544  const char *exc_type_name_norm = detail::obj_class_name(m_type.ptr());
545  if (exc_type_name_norm == nullptr) {
546  pybind11_fail("Internal error: " + std::string(called)
547  + " failed to obtain the name "
548  "of the normalized active exception type.");
549  }
550 # if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x07030a00
551  // This behavior runs the risk of masking errors in the error handling, but avoids a
552  // conflict with PyPy, which relies on the normalization here to change OSError to
553  // FileNotFoundError (https://github.com/pybind/pybind11/issues/4075).
554  m_lazy_error_string = exc_type_name_norm;
555 # else
556  if (exc_type_name_norm != m_lazy_error_string) {
557  std::string msg = std::string(called)
558  + ": MISMATCH of original and normalized "
559  "active exception types: ";
560  msg += "ORIGINAL ";
562  msg += " REPLACED BY ";
563  msg += exc_type_name_norm;
564  msg += ": " + format_value_and_trace();
566  }
567 # endif
568 #endif
569  }
570 
573 
574  std::string format_value_and_trace() const {
575  std::string result;
576  std::string message_error_string;
577  if (m_value) {
578  auto value_str = reinterpret_steal<object>(PyObject_Str(m_value.ptr()));
579  constexpr const char *message_unavailable_exc
580  = "<MESSAGE UNAVAILABLE DUE TO ANOTHER EXCEPTION>";
581  if (!value_str) {
582  message_error_string = detail::error_string();
583  result = message_unavailable_exc;
584  } else {
585  // Not using `value_str.cast<std::string>()`, to not potentially throw a secondary
586  // error_already_set that will then result in process termination (#4288).
587  auto value_bytes = reinterpret_steal<object>(
588  PyUnicode_AsEncodedString(value_str.ptr(), "utf-8", "backslashreplace"));
589  if (!value_bytes) {
590  message_error_string = detail::error_string();
591  result = message_unavailable_exc;
592  } else {
593  char *buffer = nullptr;
594  Py_ssize_t length = 0;
595  if (PyBytes_AsStringAndSize(value_bytes.ptr(), &buffer, &length) == -1) {
596  message_error_string = detail::error_string();
597  result = message_unavailable_exc;
598  } else {
599  result = std::string(buffer, static_cast<std::size_t>(length));
600  }
601  }
602  }
603 #if PY_VERSION_HEX >= 0x030B0000
604  auto notes
605  = reinterpret_steal<object>(PyObject_GetAttrString(m_value.ptr(), "__notes__"));
606  if (!notes) {
607  PyErr_Clear(); // No notes is good news.
608  } else {
609  auto len_notes = PyList_Size(notes.ptr());
610  if (len_notes < 0) {
611  result += "\nFAILURE obtaining len(__notes__): " + detail::error_string();
612  } else {
613  result += "\n__notes__ (len=" + std::to_string(len_notes) + "):";
614  for (ssize_t i = 0; i < len_notes; i++) {
615  PyObject *note = PyList_GET_ITEM(notes.ptr(), i);
616  auto note_bytes = reinterpret_steal<object>(
617  PyUnicode_AsEncodedString(note, "utf-8", "backslashreplace"));
618  if (!note_bytes) {
619  result += "\nFAILURE obtaining __notes__[" + std::to_string(i)
620  + "]: " + detail::error_string();
621  } else {
622  char *buffer = nullptr;
623  Py_ssize_t length = 0;
624  if (PyBytes_AsStringAndSize(note_bytes.ptr(), &buffer, &length)
625  == -1) {
626  result += "\nFAILURE formatting __notes__[" + std::to_string(i)
627  + "]: " + detail::error_string();
628  } else {
629  result += '\n';
630  result += std::string(buffer, static_cast<std::size_t>(length));
631  }
632  }
633  }
634  }
635  }
636 #endif
637  } else {
638  result = "<MESSAGE UNAVAILABLE>";
639  }
640  if (result.empty()) {
641  result = "<EMPTY MESSAGE>";
642  }
643 
644  bool have_trace = false;
645  if (m_trace) {
646 #if !defined(PYPY_VERSION)
647  auto *tb = reinterpret_cast<PyTracebackObject *>(m_trace.ptr());
648 
649  // Get the deepest trace possible.
650  while (tb->tb_next) {
651  tb = tb->tb_next;
652  }
653 
654  PyFrameObject *frame = tb->tb_frame;
655  Py_XINCREF(frame);
656  result += "\n\nAt:\n";
657  while (frame) {
658 # if PY_VERSION_HEX >= 0x030900B1
659  PyCodeObject *f_code = PyFrame_GetCode(frame);
660 # else
661  PyCodeObject *f_code = frame->f_code;
662  Py_INCREF(f_code);
663 # endif
664  int lineno = PyFrame_GetLineNumber(frame);
665  result += " ";
666  result += handle(f_code->co_filename).cast<std::string>();
667  result += '(';
668  result += std::to_string(lineno);
669  result += "): ";
670  result += handle(f_code->co_name).cast<std::string>();
671  result += '\n';
672  Py_DECREF(f_code);
673 # if PY_VERSION_HEX >= 0x030900B1
674  auto *b_frame = PyFrame_GetBack(frame);
675 # else
676  auto *b_frame = frame->f_back;
677  Py_XINCREF(b_frame);
678 # endif
679  Py_DECREF(frame);
680  frame = b_frame;
681  }
682 
683  have_trace = true;
684 #endif
685  }
686 
687  if (!message_error_string.empty()) {
688  if (!have_trace) {
689  result += '\n';
690  }
691  result += "\nMESSAGE UNAVAILABLE DUE TO EXCEPTION: " + message_error_string;
692  }
693 
694  return result;
695  }
696 
697  std::string const &error_string() const {
701  }
702  return m_lazy_error_string;
703  }
704 
705  void restore() {
706  if (m_restore_called) {
707  pybind11_fail("Internal error: pybind11::detail::error_fetch_and_normalize::restore() "
708  "called a second time. ORIGINAL ERROR: "
709  + error_string());
710  }
711  PyErr_Restore(m_type.inc_ref().ptr(), m_value.inc_ref().ptr(), m_trace.inc_ref().ptr());
712  m_restore_called = true;
713  }
714 
715  bool matches(handle exc) const {
716  return (PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()) != 0);
717  }
718 
719  // Not protecting these for simplicity.
721 
722 private:
723  // Only protecting invariants.
724  mutable std::string m_lazy_error_string;
725  mutable bool m_lazy_error_string_completed = false;
726  mutable bool m_restore_called = false;
727 };
728 
729 inline std::string error_string() {
730  return error_fetch_and_normalize("pybind11::detail::error_string").error_string();
731 }
732 
734 
735 class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::exception {
740 public:
744  : m_fetched_error{new detail::error_fetch_and_normalize("pybind11::error_already_set"),
745  m_fetched_error_deleter} {}
746 
750  const char *what() const noexcept override;
751 
757  void restore() { m_fetched_error->restore(); }
758 
763  void discard_as_unraisable(object err_context) {
764  restore();
765  PyErr_WriteUnraisable(err_context.ptr());
766  }
770  void discard_as_unraisable(const char *err_context) {
771  discard_as_unraisable(reinterpret_steal<object>(PYBIND11_FROM_STRING(err_context)));
772  }
773 
774  // Does nothing; provided for backwards compatibility.
775  PYBIND11_DEPRECATED("Use of error_already_set.clear() is deprecated")
776  void clear() {}
777 
781  bool matches(handle exc) const { return m_fetched_error->matches(exc); }
782 
783  const object &type() const { return m_fetched_error->m_type; }
784  const object &value() const { return m_fetched_error->m_value; }
785  const object &trace() const { return m_fetched_error->m_trace; }
786 
787 private:
788  std::shared_ptr<detail::error_fetch_and_normalize> m_fetched_error;
789 
792  static void m_fetched_error_deleter(detail::error_fetch_and_normalize *raw_ptr);
793 };
794 
797 inline void raise_from(PyObject *type, const char *message) {
798  // Based on _PyErr_FormatVFromCause:
799  // https://github.com/python/cpython/blob/467ab194fc6189d9f7310c89937c51abeac56839/Python/errors.c#L405
800  // See https://github.com/pybind/pybind11/pull/2112 for details.
801  PyObject *exc = nullptr, *val = nullptr, *val2 = nullptr, *tb = nullptr;
802 
803  assert(PyErr_Occurred());
804  PyErr_Fetch(&exc, &val, &tb);
805  PyErr_NormalizeException(&exc, &val, &tb);
806  if (tb != nullptr) {
807  PyException_SetTraceback(val, tb);
808  Py_DECREF(tb);
809  }
810  Py_DECREF(exc);
811  assert(!PyErr_Occurred());
812 
813  PyErr_SetString(type, message);
814 
815  PyErr_Fetch(&exc, &val2, &tb);
816  PyErr_NormalizeException(&exc, &val2, &tb);
817  Py_INCREF(val);
818  PyException_SetCause(val2, val);
819  PyException_SetContext(val2, val);
820  PyErr_Restore(exc, val2, tb);
821 }
822 
826 inline void raise_from(error_already_set &err, PyObject *type, const char *message) {
827  err.restore();
828  raise_from(type, message);
829 }
830 
842 bool isinstance(handle obj) {
843  return T::check_(obj);
844 }
845 
847 bool isinstance(handle obj) {
848  return detail::isinstance_generic(obj, typeid(T));
849 }
850 
851 template <>
852 inline bool isinstance<handle>(handle) = delete;
853 template <>
854 inline bool isinstance<object>(handle obj) {
855  return obj.ptr() != nullptr;
856 }
857 
860 inline bool isinstance(handle obj, handle type) {
861  const auto result = PyObject_IsInstance(obj.ptr(), type.ptr());
862  if (result == -1) {
863  throw error_already_set();
864  }
865  return result != 0;
866 }
867 
870 inline bool hasattr(handle obj, handle name) {
871  return PyObject_HasAttr(obj.ptr(), name.ptr()) == 1;
872 }
873 
874 inline bool hasattr(handle obj, const char *name) {
875  return PyObject_HasAttrString(obj.ptr(), name) == 1;
876 }
877 
878 inline void delattr(handle obj, handle name) {
879  if (PyObject_DelAttr(obj.ptr(), name.ptr()) != 0) {
880  throw error_already_set();
881  }
882 }
883 
884 inline void delattr(handle obj, const char *name) {
885  if (PyObject_DelAttrString(obj.ptr(), name) != 0) {
886  throw error_already_set();
887  }
888 }
889 
890 inline object getattr(handle obj, handle name) {
891  PyObject *result = PyObject_GetAttr(obj.ptr(), name.ptr());
892  if (!result) {
893  throw error_already_set();
894  }
895  return reinterpret_steal<object>(result);
896 }
897 
898 inline object getattr(handle obj, const char *name) {
899  PyObject *result = PyObject_GetAttrString(obj.ptr(), name);
900  if (!result) {
901  throw error_already_set();
902  }
903  return reinterpret_steal<object>(result);
904 }
905 
906 inline object getattr(handle obj, handle name, handle default_) {
907  if (PyObject *result = PyObject_GetAttr(obj.ptr(), name.ptr())) {
908  return reinterpret_steal<object>(result);
909  }
910  PyErr_Clear();
911  return reinterpret_borrow<object>(default_);
912 }
913 
914 inline object getattr(handle obj, const char *name, handle default_) {
915  if (PyObject *result = PyObject_GetAttrString(obj.ptr(), name)) {
916  return reinterpret_steal<object>(result);
917  }
918  PyErr_Clear();
919  return reinterpret_borrow<object>(default_);
920 }
921 
922 inline void setattr(handle obj, handle name, handle value) {
923  if (PyObject_SetAttr(obj.ptr(), name.ptr(), value.ptr()) != 0) {
924  throw error_already_set();
925  }
926 }
927 
928 inline void setattr(handle obj, const char *name, handle value) {
929  if (PyObject_SetAttrString(obj.ptr(), name, value.ptr()) != 0) {
930  throw error_already_set();
931  }
932 }
933 
934 inline ssize_t hash(handle obj) {
935  auto h = PyObject_Hash(obj.ptr());
936  if (h == -1) {
937  throw error_already_set();
938  }
939  return h;
940 }
941 
943 
946  if (value) {
947  if (PyInstanceMethod_Check(value.ptr())) {
948  value = PyInstanceMethod_GET_FUNCTION(value.ptr());
949  } else if (PyMethod_Check(value.ptr())) {
950  value = PyMethod_GET_FUNCTION(value.ptr());
951  }
952  }
953  return value;
954 }
955 
956 // Reimplementation of python's dict helper functions to ensure that exceptions
957 // aren't swallowed (see #2862)
958 
959 // copied from cpython _PyDict_GetItemStringWithError
960 inline PyObject *dict_getitemstring(PyObject *v, const char *key) {
961  PyObject *kv = nullptr, *rv = nullptr;
962  kv = PyUnicode_FromString(key);
963  if (kv == nullptr) {
964  throw error_already_set();
965  }
966 
967  rv = PyDict_GetItemWithError(v, kv);
968  Py_DECREF(kv);
969  if (rv == nullptr && PyErr_Occurred()) {
970  throw error_already_set();
971  }
972  return rv;
973 }
974 
975 inline PyObject *dict_getitem(PyObject *v, PyObject *key) {
976  PyObject *rv = PyDict_GetItemWithError(v, key);
977  if (rv == nullptr && PyErr_Occurred()) {
978  throw error_already_set();
979  }
980  return rv;
981 }
982 
983 inline PyObject *dict_getitemstringref(PyObject *v, const char *key) {
984 #if PY_VERSION_HEX >= 0x030D0000
985  PyObject *rv;
986  if (PyDict_GetItemStringRef(v, key, &rv) < 0) {
987  throw error_already_set();
988  }
989  return rv;
990 #else
991  PyObject *rv = dict_getitemstring(v, key);
992  if (rv == nullptr && PyErr_Occurred()) {
993  throw error_already_set();
994  }
995  Py_XINCREF(rv);
996  return rv;
997 #endif
998 }
999 
1000 // Helper aliases/functions to support implicit casting of values given to python
1001 // accessors/methods. When given a pyobject, this simply returns the pyobject as-is; for other C++
1002 // type, the value goes through pybind11::cast(obj) to convert it to an `object`.
1004 auto object_or_cast(T &&o) -> decltype(std::forward<T>(o)) {
1005  return std::forward<T>(o);
1006 }
1007 // The following casting version is implemented in cast.h:
1009 object object_or_cast(T &&o);
1010 // Match a PyObject*, which we want to convert directly to handle via its converting constructor
1011 inline handle object_or_cast(PyObject *ptr) { return ptr; }
1012 
1013 PYBIND11_WARNING_PUSH
1014 PYBIND11_WARNING_DISABLE_MSVC(4522) // warning C4522: multiple assignment operators specified
1015 template <typename Policy>
1016 class accessor : public object_api<accessor<Policy>> {
1017  using key_type = typename Policy::key_type;
1018 
1019 public:
1020  accessor(handle obj, key_type key) : obj(obj), key(std::move(key)) {}
1021  accessor(const accessor &) = default;
1022  accessor(accessor &&) noexcept = default;
1023 
1024  // accessor overload required to override default assignment operator (templates are not
1025  // allowed to replace default compiler-generated assignments).
1026  void operator=(const accessor &a) && { std::move(*this).operator=(handle(a)); }
1027  void operator=(const accessor &a) & { operator=(handle(a)); }
1028 
1029  template <typename T>
1030  void operator=(T &&value) && {
1031  Policy::set(obj, key, object_or_cast(std::forward<T>(value)));
1032  }
1033  template <typename T>
1034  void operator=(T &&value) & {
1035  get_cache() = ensure_object(object_or_cast(std::forward<T>(value)));
1036  }
1037 
1038  template <typename T = Policy>
1040  "Use of obj.attr(...) as bool is deprecated in favor of pybind11::hasattr(obj, ...)")
1041  explicit
1042  operator enable_if_t<std::is_same<T, accessor_policies::str_attr>::value
1043  || std::is_same<T, accessor_policies::obj_attr>::value,
1044  bool>() const {
1045  return hasattr(obj, key);
1046  }
1047  template <typename T = Policy>
1048  PYBIND11_DEPRECATED("Use of obj[key] as bool is deprecated in favor of obj.contains(key)")
1049  explicit
1050  operator enable_if_t<std::is_same<T, accessor_policies::generic_item>::value, bool>() const {
1051  return obj.contains(key);
1052  }
1053 
1054  // NOLINTNEXTLINE(google-explicit-constructor)
1055  operator object() const { return get_cache(); }
1056  PyObject *ptr() const { return get_cache().ptr(); }
1057  template <typename T>
1058  T cast() const {
1059  return get_cache().template cast<T>();
1060  }
1061 
1062 private:
1063  static object ensure_object(object &&o) { return std::move(o); }
1064  static object ensure_object(handle h) { return reinterpret_borrow<object>(h); }
1065 
1066  object &get_cache() const {
1067  if (!cache) {
1068  cache = Policy::get(obj, key);
1069  }
1070  return cache;
1071  }
1072 
1073 private:
1074  handle obj;
1075  key_type key;
1076  mutable object cache;
1077 };
1079 
1081 struct obj_attr {
1082  using key_type = object;
1083  static object get(handle obj, handle key) { return getattr(obj, key); }
1084  static void set(handle obj, handle key, handle val) { setattr(obj, key, val); }
1085 };
1086 
1087 struct str_attr {
1088  using key_type = const char *;
1089  static object get(handle obj, const char *key) { return getattr(obj, key); }
1090  static void set(handle obj, const char *key, handle val) { setattr(obj, key, val); }
1091 };
1092 
1094  using key_type = object;
1095 
1096  static object get(handle obj, handle key) {
1097  PyObject *result = PyObject_GetItem(obj.ptr(), key.ptr());
1098  if (!result) {
1099  throw error_already_set();
1100  }
1101  return reinterpret_steal<object>(result);
1102  }
1103 
1104  static void set(handle obj, handle key, handle val) {
1105  if (PyObject_SetItem(obj.ptr(), key.ptr(), val.ptr()) != 0) {
1106  throw error_already_set();
1107  }
1108  }
1109 };
1110 
1112  using key_type = size_t;
1113 
1115  static object get(handle obj, const IdxType &index) {
1116  PyObject *result = PySequence_GetItem(obj.ptr(), ssize_t_cast(index));
1117  if (!result) {
1118  throw error_already_set();
1119  }
1120  return reinterpret_steal<object>(result);
1121  }
1122 
1124  static void set(handle obj, const IdxType &index, handle val) {
1125  // PySequence_SetItem does not steal a reference to 'val'
1126  if (PySequence_SetItem(obj.ptr(), ssize_t_cast(index), val.ptr()) != 0) {
1127  throw error_already_set();
1128  }
1129  }
1130 };
1131 
1132 struct list_item {
1133  using key_type = size_t;
1134 
1136  static object get(handle obj, const IdxType &index) {
1137  PyObject *result = PyList_GetItem(obj.ptr(), ssize_t_cast(index));
1138  if (!result) {
1139  throw error_already_set();
1140  }
1141  return reinterpret_borrow<object>(result);
1142  }
1143 
1145  static void set(handle obj, const IdxType &index, handle val) {
1146  // PyList_SetItem steals a reference to 'val'
1147  if (PyList_SetItem(obj.ptr(), ssize_t_cast(index), val.inc_ref().ptr()) != 0) {
1148  throw error_already_set();
1149  }
1150  }
1151 };
1152 
1153 struct tuple_item {
1154  using key_type = size_t;
1155 
1157  static object get(handle obj, const IdxType &index) {
1158  PyObject *result = PyTuple_GetItem(obj.ptr(), ssize_t_cast(index));
1159  if (!result) {
1160  throw error_already_set();
1161  }
1162  return reinterpret_borrow<object>(result);
1163  }
1164 
1166  static void set(handle obj, const IdxType &index, handle val) {
1167  // PyTuple_SetItem steals a reference to 'val'
1168  if (PyTuple_SetItem(obj.ptr(), ssize_t_cast(index), val.inc_ref().ptr()) != 0) {
1169  throw error_already_set();
1170  }
1171  }
1172 };
1174 
1175 template <typename Policy>
1177 class generic_iterator : public Policy {
1179 
1180 public:
1182  using iterator_category = typename Policy::iterator_category;
1183  using value_type = typename Policy::value_type;
1184  using reference = typename Policy::reference;
1185  using pointer = typename Policy::pointer;
1186 
1187  generic_iterator() = default;
1188  generic_iterator(handle seq, ssize_t index) : Policy(seq, index) {}
1189 
1190  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1191  reference operator*() const { return Policy::dereference(); }
1192  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1193  reference operator[](difference_type n) const { return *(*this + n); }
1194  pointer operator->() const { return **this; }
1195 
1197  Policy::increment();
1198  return *this;
1199  }
1201  auto copy = *this;
1202  Policy::increment();
1203  return copy;
1204  }
1206  Policy::decrement();
1207  return *this;
1208  }
1210  auto copy = *this;
1211  Policy::decrement();
1212  return copy;
1213  }
1215  Policy::advance(n);
1216  return *this;
1217  }
1219  Policy::advance(-n);
1220  return *this;
1221  }
1222 
1223  friend It operator+(const It &a, difference_type n) {
1224  auto copy = a;
1225  return copy += n;
1226  }
1227  friend It operator+(difference_type n, const It &b) { return b + n; }
1228  friend It operator-(const It &a, difference_type n) {
1229  auto copy = a;
1230  return copy -= n;
1231  }
1232  friend difference_type operator-(const It &a, const It &b) { return a.distance_to(b); }
1233 
1234  friend bool operator==(const It &a, const It &b) { return a.equal(b); }
1235  friend bool operator!=(const It &a, const It &b) { return !(a == b); }
1236  friend bool operator<(const It &a, const It &b) { return b - a > 0; }
1237  friend bool operator>(const It &a, const It &b) { return b < a; }
1238  friend bool operator>=(const It &a, const It &b) { return !(a < b); }
1239  friend bool operator<=(const It &a, const It &b) { return !(a > b); }
1240 };
1241 
1242 PYBIND11_NAMESPACE_BEGIN(iterator_policies)
1244 template <typename T>
1245 struct arrow_proxy {
1247 
1248  // NOLINTNEXTLINE(google-explicit-constructor)
1249  arrow_proxy(T &&value) noexcept : value(std::move(value)) {}
1250  T *operator->() const { return &value; }
1251 };
1252 
1255 protected:
1256  using iterator_category = std::random_access_iterator_tag;
1258  using reference = const handle; // PR #3263
1260 
1261  sequence_fast_readonly(handle obj, ssize_t n) : ptr(PySequence_Fast_ITEMS(obj.ptr()) + n) {}
1262 
1263  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1264  reference dereference() const { return *ptr; }
1265  void increment() { ++ptr; }
1266  void decrement() { --ptr; }
1267  void advance(ssize_t n) { ptr += n; }
1268  bool equal(const sequence_fast_readonly &b) const { return ptr == b.ptr; }
1269  ssize_t distance_to(const sequence_fast_readonly &b) const { return ptr - b.ptr; }
1270 
1271 private:
1272  PyObject **ptr;
1273 };
1274 
1277 protected:
1278  using iterator_category = std::random_access_iterator_tag;
1282 
1283  sequence_slow_readwrite(handle obj, ssize_t index) : obj(obj), index(index) {}
1284 
1285  reference dereference() const { return {obj, static_cast<size_t>(index)}; }
1286  void increment() { ++index; }
1287  void decrement() { --index; }
1288  void advance(ssize_t n) { index += n; }
1289  bool equal(const sequence_slow_readwrite &b) const { return index == b.index; }
1290  ssize_t distance_to(const sequence_slow_readwrite &b) const { return index - b.index; }
1291 
1292 private:
1295 };
1296 
1299 protected:
1300  using iterator_category = std::forward_iterator_tag;
1301  using value_type = std::pair<handle, handle>;
1302  using reference = const value_type; // PR #3263
1304 
1305  dict_readonly() = default;
1306  dict_readonly(handle obj, ssize_t pos) : obj(obj), pos(pos) { increment(); }
1307 
1308  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1309  reference dereference() const { return {key, value}; }
1310  void increment() {
1311  if (PyDict_Next(obj.ptr(), &pos, &key, &value) == 0) {
1312  pos = -1;
1313  }
1314  }
1315  bool equal(const dict_readonly &b) const { return pos == b.pos; }
1316 
1317 private:
1319  PyObject *key = nullptr, *value = nullptr;
1320  ssize_t pos = -1;
1321 };
1322 PYBIND11_NAMESPACE_END(iterator_policies)
1323 
1324 #if !defined(PYPY_VERSION)
1327 #else
1330 #endif
1331 
1334 
1335 inline bool PyIterable_Check(PyObject *obj) {
1336  PyObject *iter = PyObject_GetIter(obj);
1337  if (iter) {
1338  Py_DECREF(iter);
1339  return true;
1340  }
1341  PyErr_Clear();
1342  return false;
1343 }
1344 
1345 inline bool PyNone_Check(PyObject *o) { return o == Py_None; }
1346 inline bool PyEllipsis_Check(PyObject *o) { return o == Py_Ellipsis; }
1347 
1348 #ifdef PYBIND11_STR_LEGACY_PERMISSIVE
1349 inline bool PyUnicode_Check_Permissive(PyObject *o) {
1350  return PyUnicode_Check(o) || PYBIND11_BYTES_CHECK(o);
1351 }
1352 # define PYBIND11_STR_CHECK_FUN detail::PyUnicode_Check_Permissive
1353 #else
1354 # define PYBIND11_STR_CHECK_FUN PyUnicode_Check
1355 #endif
1356 
1357 inline bool PyStaticMethod_Check(PyObject *o) { return o->ob_type == &PyStaticMethod_Type; }
1358 
1359 class kwargs_proxy : public handle {
1360 public:
1361  explicit kwargs_proxy(handle h) : handle(h) {}
1362 };
1363 
1364 class args_proxy : public handle {
1365 public:
1366  explicit args_proxy(handle h) : handle(h) {}
1367  kwargs_proxy operator*() const { return kwargs_proxy(*this); }
1368 };
1369 
1371 template <typename T>
1372 using is_keyword = std::is_base_of<arg, T>;
1373 template <typename T>
1374 using is_s_unpacking = std::is_same<args_proxy, T>; // * unpacking
1375 template <typename T>
1376 using is_ds_unpacking = std::is_same<kwargs_proxy, T>; // ** unpacking
1377 template <typename T>
1379 template <typename T>
1381 
1382 // Call argument collector forward declarations
1383 template <return_value_policy policy = return_value_policy::automatic_reference>
1384 class simple_collector;
1385 template <return_value_policy policy = return_value_policy::automatic_reference>
1386 class unpacking_collector;
1387 
1389 
1390 // TODO: After the deprecated constructors are removed, this macro can be simplified by
1391 // inheriting ctors: `using Parent::Parent`. It's not an option right now because
1392 // the `using` statement triggers the parent deprecation warning even if the ctor
1393 // isn't even used.
1394 #define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
1395 public: \
1396  PYBIND11_DEPRECATED("Use reinterpret_borrow<" #Name ">() or reinterpret_steal<" #Name ">()") \
1397  Name(handle h, bool is_borrowed) \
1398  : Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) {} \
1399  Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) {} \
1400  Name(handle h, stolen_t) : Parent(h, stolen_t{}) {} \
1401  PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \
1402  bool check() const { return m_ptr != nullptr && (CheckFun(m_ptr) != 0); } \
1403  static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \
1404  template <typename Policy_> /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1405  Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) {}
1406 
1407 #define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \
1408  PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
1409  /* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
1410  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1411  Name(const object &o) \
1412  : Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
1413  if (!m_ptr) \
1414  throw ::pybind11::error_already_set(); \
1415  } \
1416  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1417  Name(object &&o) : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
1418  if (!m_ptr) \
1419  throw ::pybind11::error_already_set(); \
1420  }
1421 
1422 #define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun) \
1423  PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \
1424  Name() = default;
1425 
1426 #define PYBIND11_OBJECT_CHECK_FAILED(Name, o_ptr) \
1427  ::pybind11::type_error("Object of type '" \
1428  + ::pybind11::detail::get_fully_qualified_tp_name(Py_TYPE(o_ptr)) \
1429  + "' is not an instance of '" #Name "'")
1430 
1431 #define PYBIND11_OBJECT(Name, Parent, CheckFun) \
1432  PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
1433  /* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
1434  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1435  Name(const object &o) : Parent(o) { \
1436  if (m_ptr && !check_(m_ptr)) \
1437  throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
1438  } \
1439  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1440  Name(object &&o) : Parent(std::move(o)) { \
1441  if (m_ptr && !check_(m_ptr)) \
1442  throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
1443  }
1444 
1445 #define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun) \
1446  PYBIND11_OBJECT(Name, Parent, CheckFun) \
1447  Name() = default;
1448 
1451 
1460 class iterator : public object {
1461 public:
1462  using iterator_category = std::input_iterator_tag;
1465  using reference = const handle; // PR #3263
1466  using pointer = const handle *;
1467 
1468  PYBIND11_OBJECT_DEFAULT(iterator, object, PyIter_Check)
1469 
1470  iterator &operator++() {
1471  advance();
1472  return *this;
1473  }
1474 
1476  auto rv = *this;
1477  advance();
1478  return rv;
1479  }
1480 
1481  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1483  if (m_ptr && !value.ptr()) {
1484  auto &self = const_cast<iterator &>(*this);
1485  self.advance();
1486  }
1487  return value;
1488  }
1489 
1491  operator*();
1492  return &value;
1493  }
1494 
1508  static iterator sentinel() { return {}; }
1509 
1510  friend bool operator==(const iterator &a, const iterator &b) { return a->ptr() == b->ptr(); }
1511  friend bool operator!=(const iterator &a, const iterator &b) { return a->ptr() != b->ptr(); }
1512 
1513 private:
1514  void advance() {
1515  value = reinterpret_steal<object>(PyIter_Next(m_ptr));
1516  if (value.ptr() == nullptr && PyErr_Occurred()) {
1517  throw error_already_set();
1518  }
1519  }
1520 
1521 private:
1522  object value = {};
1523 };
1524 
1525 class type : public object {
1526 public:
1527  PYBIND11_OBJECT(type, object, PyType_Check)
1528 
1529 
1530  static handle handle_of(handle h) { return handle((PyObject *) Py_TYPE(h.ptr())); }
1531 
1533  static type of(handle h) { return type(type::handle_of(h), borrowed_t{}); }
1534 
1535  // Defined in pybind11/cast.h
1539  template <typename T>
1540  static handle handle_of();
1541 
1545  template <typename T>
1546  static type of() {
1547  return type(type::handle_of<T>(), borrowed_t{});
1548  }
1549 };
1550 
1551 class iterable : public object {
1552 public:
1554 };
1555 
1556 class bytes;
1557 
1558 class str : public object {
1559 public:
1561 
1563  str(const char *c, const SzType &n)
1564  : object(PyUnicode_FromStringAndSize(c, ssize_t_cast(n)), stolen_t{}) {
1565  if (!m_ptr) {
1566  if (PyErr_Occurred()) {
1567  throw error_already_set();
1568  }
1569  pybind11_fail("Could not allocate string object!");
1570  }
1571  }
1572 
1573  // 'explicit' is explicitly omitted from the following constructors to allow implicit
1574  // conversion to py::str from C++ string-like objects
1575  // NOLINTNEXTLINE(google-explicit-constructor)
1576  str(const char *c = "") : object(PyUnicode_FromString(c), stolen_t{}) {
1577  if (!m_ptr) {
1578  if (PyErr_Occurred()) {
1579  throw error_already_set();
1580  }
1581  pybind11_fail("Could not allocate string object!");
1582  }
1583  }
1584 
1585  // NOLINTNEXTLINE(google-explicit-constructor)
1586  str(const std::string &s) : str(s.data(), s.size()) {}
1587 
1588 #ifdef PYBIND11_HAS_STRING_VIEW
1589  // enable_if is needed to avoid "ambiguous conversion" errors (see PR #3521).
1591  // NOLINTNEXTLINE(google-explicit-constructor)
1592  str(T s) : str(s.data(), s.size()) {}
1593 
1594 # ifdef PYBIND11_HAS_U8STRING
1595  // reinterpret_cast here is safe (C++20 guarantees char8_t has the same size/alignment as char)
1596  // NOLINTNEXTLINE(google-explicit-constructor)
1597  str(std::u8string_view s) : str(reinterpret_cast<const char *>(s.data()), s.size()) {}
1598 # endif
1599 
1600 #endif
1601 
1602  explicit str(const bytes &b);
1603 
1608  explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) {
1609  if (!m_ptr) {
1610  throw error_already_set();
1611  }
1612  }
1613 
1614  // NOLINTNEXTLINE(google-explicit-constructor)
1615  operator std::string() const {
1616  object temp = *this;
1617  if (PyUnicode_Check(m_ptr)) {
1618  temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(m_ptr));
1619  if (!temp) {
1620  throw error_already_set();
1621  }
1622  }
1623  char *buffer = nullptr;
1624  ssize_t length = 0;
1625  if (PyBytes_AsStringAndSize(temp.ptr(), &buffer, &length) != 0) {
1626  throw error_already_set();
1627  }
1628  return std::string(buffer, (size_t) length);
1629  }
1630 
1631  template <typename... Args>
1632  str format(Args &&...args) const {
1633  return attr("format")(std::forward<Args>(args)...);
1634  }
1635 
1636 private:
1638  static PyObject *raw_str(PyObject *op) {
1639  PyObject *str_value = PyObject_Str(op);
1640  return str_value;
1641  }
1642 };
1644 
1645 inline namespace literals {
1649 inline str
1650 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5
1651 operator"" _s // gcc 4.8.5 insists on having a space (hard error).
1652 #else
1653 operator""_s // clang 17 generates a deprecation warning if there is a space.
1654 #endif
1655  (const char *s, size_t size) {
1656  return {s, size};
1657 }
1658 } // namespace literals
1659 
1662 class bytes : public object {
1663 public:
1665 
1666  // Allow implicit conversion:
1667  // NOLINTNEXTLINE(google-explicit-constructor)
1668  bytes(const char *c = "") : object(PYBIND11_BYTES_FROM_STRING(c), stolen_t{}) {
1669  if (!m_ptr) {
1670  pybind11_fail("Could not allocate bytes object!");
1671  }
1672  }
1673 
1675  bytes(const char *c, const SzType &n)
1677  if (!m_ptr) {
1678  pybind11_fail("Could not allocate bytes object!");
1679  }
1680  }
1681 
1682  // Allow implicit conversion:
1683  // NOLINTNEXTLINE(google-explicit-constructor)
1684  bytes(const std::string &s) : bytes(s.data(), s.size()) {}
1685 
1686  explicit bytes(const pybind11::str &s);
1687 
1688  // NOLINTNEXTLINE(google-explicit-constructor)
1689  operator std::string() const { return string_op<std::string>(); }
1690 
1691 #ifdef PYBIND11_HAS_STRING_VIEW
1692  // enable_if is needed to avoid "ambiguous conversion" errors (see PR #3521).
1694  // NOLINTNEXTLINE(google-explicit-constructor)
1695  bytes(T s) : bytes(s.data(), s.size()) {}
1696 
1697  // Obtain a string view that views the current `bytes` buffer value. Note that this is only
1698  // valid so long as the `bytes` instance remains alive and so generally should not outlive the
1699  // lifetime of the `bytes` instance.
1700  // NOLINTNEXTLINE(google-explicit-constructor)
1701  operator std::string_view() const { return string_op<std::string_view>(); }
1702 #endif
1703 private:
1704  template <typename T>
1705  T string_op() const {
1706  char *buffer = nullptr;
1707  ssize_t length = 0;
1708  if (PyBytes_AsStringAndSize(m_ptr, &buffer, &length) != 0) {
1709  throw error_already_set();
1710  }
1711  return {buffer, static_cast<size_t>(length)};
1712  }
1713 };
1714 // Note: breathe >= 4.17.0 will fail to build docs if the below two constructors
1715 // are included in the doxygen group; close here and reopen after as a workaround
1717 
1718 inline bytes::bytes(const pybind11::str &s) {
1719  object temp = s;
1720  if (PyUnicode_Check(s.ptr())) {
1721  temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(s.ptr()));
1722  if (!temp) {
1723  throw error_already_set();
1724  }
1725  }
1726  char *buffer = nullptr;
1727  ssize_t length = 0;
1728  if (PyBytes_AsStringAndSize(temp.ptr(), &buffer, &length) != 0) {
1729  throw error_already_set();
1730  }
1731  auto obj = reinterpret_steal<object>(PYBIND11_BYTES_FROM_STRING_AND_SIZE(buffer, length));
1732  if (!obj) {
1733  pybind11_fail("Could not allocate bytes object!");
1734  }
1735  m_ptr = obj.release().ptr();
1736 }
1737 
1738 inline str::str(const bytes &b) {
1739  char *buffer = nullptr;
1740  ssize_t length = 0;
1741  if (PyBytes_AsStringAndSize(b.ptr(), &buffer, &length) != 0) {
1742  throw error_already_set();
1743  }
1744  auto obj = reinterpret_steal<object>(PyUnicode_FromStringAndSize(buffer, length));
1745  if (!obj) {
1746  if (PyErr_Occurred()) {
1747  throw error_already_set();
1748  }
1749  pybind11_fail("Could not allocate string object!");
1750  }
1751  m_ptr = obj.release().ptr();
1752 }
1753 
1756 class bytearray : public object {
1757 public:
1758  PYBIND11_OBJECT_CVT(bytearray, object, PyByteArray_Check, PyByteArray_FromObject)
1759 
1761  bytearray(const char *c, const SzType &n)
1762  : object(PyByteArray_FromStringAndSize(c, ssize_t_cast(n)), stolen_t{}) {
1763  if (!m_ptr) {
1764  pybind11_fail("Could not allocate bytearray object!");
1765  }
1766  }
1767 
1768  bytearray() : bytearray("", 0) {}
1769 
1770  explicit bytearray(const std::string &s) : bytearray(s.data(), s.size()) {}
1771 
1772  size_t size() const { return static_cast<size_t>(PyByteArray_Size(m_ptr)); }
1773 
1774  explicit operator std::string() const {
1775  char *buffer = PyByteArray_AS_STRING(m_ptr);
1776  ssize_t size = PyByteArray_GET_SIZE(m_ptr);
1777  return std::string(buffer, static_cast<size_t>(size));
1778  }
1779 };
1780 // Note: breathe >= 4.17.0 will fail to build docs if the below two constructors
1781 // are included in the doxygen group; close here and reopen after as a workaround
1783 
1786 class none : public object {
1787 public:
1789  none() : object(Py_None, borrowed_t{}) {}
1790 };
1791 
1792 class ellipsis : public object {
1793 public:
1795  ellipsis() : object(Py_Ellipsis, borrowed_t{}) {}
1796 };
1797 
1798 class bool_ : public object {
1799 public:
1800  PYBIND11_OBJECT_CVT(bool_, object, PyBool_Check, raw_bool)
1801  bool_() : object(Py_False, borrowed_t{}) {}
1802  // Allow implicit conversion from and to `bool`:
1803  // NOLINTNEXTLINE(google-explicit-constructor)
1804  bool_(bool value) : object(value ? Py_True : Py_False, borrowed_t{}) {}
1805  // NOLINTNEXTLINE(google-explicit-constructor)
1806  operator bool() const { return (m_ptr != nullptr) && PyLong_AsLong(m_ptr) != 0; }
1807 
1808 private:
1810  static PyObject *raw_bool(PyObject *op) {
1811  const auto value = PyObject_IsTrue(op);
1812  if (value == -1) {
1813  return nullptr;
1814  }
1815  return handle(value != 0 ? Py_True : Py_False).inc_ref().ptr();
1816  }
1817 };
1818 
1820 // Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1;
1821 // otherwise you get back the unsigned long or unsigned long long value cast to (Unsigned).
1822 // (The distinction is critically important when casting a returned -1 error value to some other
1823 // unsigned type: (A)-1 != (B)-1 when A and B are unsigned types of different sizes).
1824 template <typename Unsigned>
1825 Unsigned as_unsigned(PyObject *o) {
1826  if (sizeof(Unsigned) <= sizeof(unsigned long)) {
1827  unsigned long v = PyLong_AsUnsignedLong(o);
1828  return v == (unsigned long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
1829  }
1830  unsigned long long v = PyLong_AsUnsignedLongLong(o);
1831  return v == (unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
1832 }
1834 
1835 class int_ : public object {
1836 public:
1837  PYBIND11_OBJECT_CVT(int_, object, PYBIND11_LONG_CHECK, PyNumber_Long)
1838  int_() : object(PyLong_FromLong(0), stolen_t{}) {}
1839  // Allow implicit conversion from C++ integral types:
1841  // NOLINTNEXTLINE(google-explicit-constructor)
1843  if (sizeof(T) <= sizeof(long)) {
1845  m_ptr = PyLong_FromLong((long) value);
1846  } else {
1847  m_ptr = PyLong_FromUnsignedLong((unsigned long) value);
1848  }
1849  } else {
1851  m_ptr = PyLong_FromLongLong((long long) value);
1852  } else {
1853  m_ptr = PyLong_FromUnsignedLongLong((unsigned long long) value);
1854  }
1855  }
1856  if (!m_ptr) {
1857  pybind11_fail("Could not allocate int object!");
1858  }
1859  }
1860 
1862  // NOLINTNEXTLINE(google-explicit-constructor)
1863  operator T() const {
1864  return std::is_unsigned<T>::value ? detail::as_unsigned<T>(m_ptr)
1865  : sizeof(T) <= sizeof(long) ? (T) PyLong_AsLong(m_ptr)
1866  : (T) PYBIND11_LONG_AS_LONGLONG(m_ptr);
1867  }
1868 };
1869 
1870 class float_ : public object {
1871 public:
1872  PYBIND11_OBJECT_CVT(float_, object, PyFloat_Check, PyNumber_Float)
1873  // Allow implicit conversion from float/double:
1874  // NOLINTNEXTLINE(google-explicit-constructor)
1875  float_(float value) : object(PyFloat_FromDouble((double) value), stolen_t{}) {
1876  if (!m_ptr) {
1877  pybind11_fail("Could not allocate float object!");
1878  }
1879  }
1880  // NOLINTNEXTLINE(google-explicit-constructor)
1881  float_(double value = .0) : object(PyFloat_FromDouble((double) value), stolen_t{}) {
1882  if (!m_ptr) {
1883  pybind11_fail("Could not allocate float object!");
1884  }
1885  }
1886  // NOLINTNEXTLINE(google-explicit-constructor)
1887  operator float() const { return (float) PyFloat_AsDouble(m_ptr); }
1888  // NOLINTNEXTLINE(google-explicit-constructor)
1889  operator double() const { return (double) PyFloat_AsDouble(m_ptr); }
1890 };
1891 
1892 class weakref : public object {
1893 public:
1894  PYBIND11_OBJECT_CVT_DEFAULT(weakref, object, PyWeakref_Check, raw_weakref)
1895  explicit weakref(handle obj, handle callback = {})
1896  : object(PyWeakref_NewRef(obj.ptr(), callback.ptr()), stolen_t{}) {
1897  if (!m_ptr) {
1898  if (PyErr_Occurred()) {
1899  throw error_already_set();
1900  }
1901  pybind11_fail("Could not allocate weak reference!");
1902  }
1903  }
1904 
1905 private:
1906  static PyObject *raw_weakref(PyObject *o) { return PyWeakref_NewRef(o, nullptr); }
1907 };
1908 
1909 class slice : public object {
1910 public:
1911  PYBIND11_OBJECT_DEFAULT(slice, object, PySlice_Check)
1913  : object(PySlice_New(start.ptr(), stop.ptr(), step.ptr()), stolen_t{}) {
1914  if (!m_ptr) {
1915  pybind11_fail("Could not allocate slice object!");
1916  }
1917  }
1918 
1919 #ifdef PYBIND11_HAS_OPTIONAL
1920  slice(std::optional<ssize_t> start, std::optional<ssize_t> stop, std::optional<ssize_t> step)
1921  : slice(index_to_object(start), index_to_object(stop), index_to_object(step)) {}
1922 #else
1923  slice(ssize_t start_, ssize_t stop_, ssize_t step_)
1924  : slice(int_(start_), int_(stop_), int_(step_)) {}
1925 #endif
1926 
1927  bool
1928  compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const {
1929  return PySlice_GetIndicesEx((PYBIND11_SLICE_OBJECT *) m_ptr,
1930  (ssize_t) length,
1931  (ssize_t *) start,
1932  (ssize_t *) stop,
1933  (ssize_t *) step,
1934  (ssize_t *) slicelength)
1935  == 0;
1936  }
1937  bool compute(
1938  ssize_t length, ssize_t *start, ssize_t *stop, ssize_t *step, ssize_t *slicelength) const {
1939  return PySlice_GetIndicesEx(
1940  (PYBIND11_SLICE_OBJECT *) m_ptr, length, start, stop, step, slicelength)
1941  == 0;
1942  }
1943 
1944 private:
1945  template <typename T>
1946  static object index_to_object(T index) {
1947  return index ? object(int_(*index)) : object(none());
1948  }
1949 };
1950 
1951 class capsule : public object {
1952 public:
1953  PYBIND11_OBJECT_DEFAULT(capsule, object, PyCapsule_CheckExact)
1954  PYBIND11_DEPRECATED("Use reinterpret_borrow<capsule>() or reinterpret_steal<capsule>()")
1955  capsule(PyObject *ptr, bool is_borrowed)
1956  : object(is_borrowed ? object(ptr, borrowed_t{}) : object(ptr, stolen_t{})) {}
1957 
1958  explicit capsule(const void *value,
1959  const char *name = nullptr,
1960  PyCapsule_Destructor destructor = nullptr)
1961  : object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) {
1962  if (!m_ptr) {
1963  throw error_already_set();
1964  }
1965  }
1966 
1967  PYBIND11_DEPRECATED("Please use the ctor with value, name, destructor args")
1968  capsule(const void *value, PyCapsule_Destructor destructor)
1969  : object(PyCapsule_New(const_cast<void *>(value), nullptr, destructor), stolen_t{}) {
1970  if (!m_ptr) {
1971  throw error_already_set();
1972  }
1973  }
1974 
1976  capsule(const void *value, void (*destructor)(void *)) {
1977  initialize_with_void_ptr_destructor(value, nullptr, destructor);
1978  }
1979 
1980  capsule(const void *value, const char *name, void (*destructor)(void *)) {
1981  initialize_with_void_ptr_destructor(value, name, destructor);
1982  }
1983 
1984  explicit capsule(void (*destructor)()) {
1985  m_ptr = PyCapsule_New(reinterpret_cast<void *>(destructor), nullptr, [](PyObject *o) {
1986  const char *name = get_name_in_error_scope(o);
1987  auto destructor = reinterpret_cast<void (*)()>(PyCapsule_GetPointer(o, name));
1988  if (destructor == nullptr) {
1989  throw error_already_set();
1990  }
1991  destructor();
1992  });
1993 
1994  if (!m_ptr) {
1995  throw error_already_set();
1996  }
1997  }
1998 
1999  template <typename T>
2000  operator T *() const { // NOLINT(google-explicit-constructor)
2001  return get_pointer<T>();
2002  }
2003 
2005  template <typename T = void>
2006  T *get_pointer() const {
2007  const auto *name = this->name();
2008  T *result = static_cast<T *>(PyCapsule_GetPointer(m_ptr, name));
2009  if (!result) {
2010  throw error_already_set();
2011  }
2012  return result;
2013  }
2014 
2016  void set_pointer(const void *value) {
2017  if (PyCapsule_SetPointer(m_ptr, const_cast<void *>(value)) != 0) {
2018  throw error_already_set();
2019  }
2020  }
2021 
2022  const char *name() const {
2023  const char *name = PyCapsule_GetName(m_ptr);
2024  if ((name == nullptr) && PyErr_Occurred()) {
2025  throw error_already_set();
2026  }
2027  return name;
2028  }
2029 
2031  void set_name(const char *new_name) {
2032  if (PyCapsule_SetName(m_ptr, new_name) != 0) {
2033  throw error_already_set();
2034  }
2035  }
2036 
2037 private:
2038  static const char *get_name_in_error_scope(PyObject *o) {
2039  error_scope error_guard;
2040 
2041  const char *name = PyCapsule_GetName(o);
2042  if ((name == nullptr) && PyErr_Occurred()) {
2043  // write out and consume error raised by call to PyCapsule_GetName
2044  PyErr_WriteUnraisable(o);
2045  }
2046 
2047  return name;
2048  }
2049 
2050  void initialize_with_void_ptr_destructor(const void *value,
2051  const char *name,
2052  void (*destructor)(void *)) {
2053  m_ptr = PyCapsule_New(const_cast<void *>(value), name, [](PyObject *o) {
2054  // guard if destructor called while err indicator is set
2055  error_scope error_guard;
2056  auto destructor = reinterpret_cast<void (*)(void *)>(PyCapsule_GetContext(o));
2057  if (destructor == nullptr && PyErr_Occurred()) {
2058  throw error_already_set();
2059  }
2060  const char *name = get_name_in_error_scope(o);
2061  void *ptr = PyCapsule_GetPointer(o, name);
2062  if (ptr == nullptr) {
2063  throw error_already_set();
2064  }
2065 
2066  if (destructor != nullptr) {
2067  destructor(ptr);
2068  }
2069  });
2070 
2071  if (!m_ptr || PyCapsule_SetContext(m_ptr, reinterpret_cast<void *>(destructor)) != 0) {
2072  throw error_already_set();
2073  }
2074  }
2075 };
2076 
2077 class tuple : public object {
2078 public:
2079  PYBIND11_OBJECT_CVT(tuple, object, PyTuple_Check, PySequence_Tuple)
2080  template <typename SzType = ssize_t,
2082  // Some compilers generate link errors when using `const SzType &` here:
2083  explicit tuple(SzType size = 0) : object(PyTuple_New(ssize_t_cast(size)), stolen_t{}) {
2084  if (!m_ptr) {
2085  pybind11_fail("Could not allocate tuple object!");
2086  }
2087  }
2088  size_t size() const { return (size_t) PyTuple_Size(m_ptr); }
2089  bool empty() const { return size() == 0; }
2090  detail::tuple_accessor operator[](size_t index) const { return {*this, index}; }
2093  return object::operator[](std::forward<T>(o));
2094  }
2095  detail::tuple_iterator begin() const { return {*this, 0}; }
2096  detail::tuple_iterator end() const { return {*this, PyTuple_GET_SIZE(m_ptr)}; }
2097 };
2098 
2099 // We need to put this into a separate function because the Intel compiler
2100 // fails to compile enable_if_t<all_of<is_keyword_or_ds<Args>...>::value> part below
2101 // (tested with ICC 2021.1 Beta 20200827).
2102 template <typename... Args>
2103 constexpr bool args_are_all_keyword_or_ds() {
2104  return detail::all_of<detail::is_keyword_or_ds<Args>...>::value;
2105 }
2106 
2107 class dict : public object {
2108 public:
2109  PYBIND11_OBJECT_CVT(dict, object, PyDict_Check, raw_dict)
2110  dict() : object(PyDict_New(), stolen_t{}) {
2111  if (!m_ptr) {
2112  pybind11_fail("Could not allocate dict object!");
2113  }
2114  }
2115  template <typename... Args,
2116  typename = detail::enable_if_t<args_are_all_keyword_or_ds<Args...>()>,
2117  // MSVC workaround: it can't compile an out-of-line definition, so defer the
2118  // collector
2119  typename collector = detail::deferred_t<detail::unpacking_collector<>, Args...>>
2120  explicit dict(Args &&...args) : dict(collector(std::forward<Args>(args)...).kwargs()) {}
2121 
2122  size_t size() const { return (size_t) PyDict_Size(m_ptr); }
2123  bool empty() const { return size() == 0; }
2124  detail::dict_iterator begin() const { return {*this, 0}; }
2125  detail::dict_iterator end() const { return {}; }
2126  void clear() /* py-non-const */ { PyDict_Clear(ptr()); }
2127  template <typename T>
2128  bool contains(T &&key) const {
2129  auto result = PyDict_Contains(m_ptr, detail::object_or_cast(std::forward<T>(key)).ptr());
2130  if (result == -1) {
2131  throw error_already_set();
2132  }
2133  return result == 1;
2134  }
2135 
2136 private:
2138  static PyObject *raw_dict(PyObject *op) {
2139  if (PyDict_Check(op)) {
2140  return handle(op).inc_ref().ptr();
2141  }
2142  return PyObject_CallFunctionObjArgs((PyObject *) &PyDict_Type, op, nullptr);
2143  }
2144 };
2145 
2146 class sequence : public object {
2147 public:
2148  PYBIND11_OBJECT_DEFAULT(sequence, object, PySequence_Check)
2149  size_t size() const {
2150  ssize_t result = PySequence_Size(m_ptr);
2151  if (result == -1) {
2152  throw error_already_set();
2153  }
2154  return (size_t) result;
2155  }
2156  bool empty() const { return size() == 0; }
2157  detail::sequence_accessor operator[](size_t index) const { return {*this, index}; }
2160  return object::operator[](std::forward<T>(o));
2161  }
2162  detail::sequence_iterator begin() const { return {*this, 0}; }
2163  detail::sequence_iterator end() const { return {*this, PySequence_Size(m_ptr)}; }
2164 };
2165 
2166 class list : public object {
2167 public:
2168  PYBIND11_OBJECT_CVT(list, object, PyList_Check, PySequence_List)
2169  template <typename SzType = ssize_t,
2171  // Some compilers generate link errors when using `const SzType &` here:
2172  explicit list(SzType size = 0) : object(PyList_New(ssize_t_cast(size)), stolen_t{}) {
2173  if (!m_ptr) {
2174  pybind11_fail("Could not allocate list object!");
2175  }
2176  }
2177  size_t size() const { return (size_t) PyList_Size(m_ptr); }
2178  bool empty() const { return size() == 0; }
2179  detail::list_accessor operator[](size_t index) const { return {*this, index}; }
2182  return object::operator[](std::forward<T>(o));
2183  }
2184  detail::list_iterator begin() const { return {*this, 0}; }
2185  detail::list_iterator end() const { return {*this, PyList_GET_SIZE(m_ptr)}; }
2186  template <typename T>
2187  void append(T &&val) /* py-non-const */ {
2188  if (PyList_Append(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) != 0) {
2189  throw error_already_set();
2190  }
2191  }
2192  template <typename IdxType,
2193  typename ValType,
2195  void insert(const IdxType &index, ValType &&val) /* py-non-const */ {
2196  if (PyList_Insert(m_ptr,
2197  ssize_t_cast(index),
2198  detail::object_or_cast(std::forward<ValType>(val)).ptr())
2199  != 0) {
2200  throw error_already_set();
2201  }
2202  }
2203  void clear() /* py-non-const */ {
2204  if (PyList_SetSlice(m_ptr, 0, PyList_Size(m_ptr), nullptr) == -1) {
2205  throw error_already_set();
2206  }
2207  }
2208 };
2209 
2210 class args : public tuple {
2211  PYBIND11_OBJECT_DEFAULT(args, tuple, PyTuple_Check)
2212 };
2213 class kwargs : public dict {
2214  PYBIND11_OBJECT_DEFAULT(kwargs, dict, PyDict_Check)
2215 };
2216 
2217 class anyset : public object {
2218 public:
2219  PYBIND11_OBJECT(anyset, object, PyAnySet_Check)
2220  size_t size() const { return static_cast<size_t>(PySet_Size(m_ptr)); }
2221  bool empty() const { return size() == 0; }
2222  template <typename T>
2223  bool contains(T &&val) const {
2224  auto result = PySet_Contains(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr());
2225  if (result == -1) {
2226  throw error_already_set();
2227  }
2228  return result == 1;
2229  }
2230 };
2231 
2232 class set : public anyset {
2233 public:
2234  PYBIND11_OBJECT_CVT(set, anyset, PySet_Check, PySet_New)
2235  set() : anyset(PySet_New(nullptr), stolen_t{}) {
2236  if (!m_ptr) {
2237  pybind11_fail("Could not allocate set object!");
2238  }
2239  }
2240  template <typename T>
2241  bool add(T &&val) /* py-non-const */ {
2242  return PySet_Add(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 0;
2243  }
2244  void clear() /* py-non-const */ { PySet_Clear(m_ptr); }
2245 };
2246 
2247 class frozenset : public anyset {
2248 public:
2249  PYBIND11_OBJECT_CVT(frozenset, anyset, PyFrozenSet_Check, PyFrozenSet_New)
2250 };
2251 
2252 class function : public object {
2253 public:
2254  PYBIND11_OBJECT_DEFAULT(function, object, PyCallable_Check)
2256  handle fun = detail::get_function(m_ptr);
2257  if (fun && PyCFunction_Check(fun.ptr())) {
2258  return fun;
2259  }
2260  return handle();
2261  }
2262  bool is_cpp_function() const { return (bool) cpp_function(); }
2263 };
2264 
2265 class staticmethod : public object {
2266 public:
2267  PYBIND11_OBJECT_CVT(staticmethod, object, detail::PyStaticMethod_Check, PyStaticMethod_New)
2268 };
2269 
2270 class buffer : public object {
2271 public:
2272  PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
2273 
2274  buffer_info request(bool writable = false) const {
2275  int flags = PyBUF_STRIDES | PyBUF_FORMAT;
2276  if (writable) {
2277  flags |= PyBUF_WRITABLE;
2278  }
2279  auto *view = new Py_buffer();
2280  if (PyObject_GetBuffer(m_ptr, view, flags) != 0) {
2281  delete view;
2282  throw error_already_set();
2283  }
2284  return buffer_info(view);
2285  }
2286 };
2287 
2288 class memoryview : public object {
2289 public:
2290  PYBIND11_OBJECT_CVT(memoryview, object, PyMemoryView_Check, PyMemoryView_FromObject)
2291 
2292 
2301  explicit memoryview(const buffer_info &info) {
2302  if (!info.view()) {
2303  pybind11_fail("Prohibited to create memoryview without Py_buffer");
2304  }
2305  // Note: PyMemoryView_FromBuffer never increments obj reference.
2306  m_ptr = (info.view()->obj) ? PyMemoryView_FromObject(info.view()->obj)
2307  : PyMemoryView_FromBuffer(info.view());
2308  if (!m_ptr) {
2309  pybind11_fail("Unable to create memoryview from buffer descriptor");
2310  }
2311  }
2312 
2337  static memoryview from_buffer(void *ptr,
2338  ssize_t itemsize,
2339  const char *format,
2340  detail::any_container<ssize_t> shape,
2341  detail::any_container<ssize_t> strides,
2342  bool readonly = false);
2343 
2344  static memoryview from_buffer(const void *ptr,
2345  ssize_t itemsize,
2346  const char *format,
2347  detail::any_container<ssize_t> shape,
2348  detail::any_container<ssize_t> strides) {
2349  return memoryview::from_buffer(
2350  const_cast<void *>(ptr), itemsize, format, std::move(shape), std::move(strides), true);
2351  }
2352 
2353  template <typename T>
2354  static memoryview from_buffer(T *ptr,
2355  detail::any_container<ssize_t> shape,
2356  detail::any_container<ssize_t> strides,
2357  bool readonly = false) {
2358  return memoryview::from_buffer(reinterpret_cast<void *>(ptr),
2359  sizeof(T),
2361  std::move(shape),
2362  std::move(strides),
2363  readonly);
2364  }
2365 
2366  template <typename T>
2367  static memoryview from_buffer(const T *ptr,
2368  detail::any_container<ssize_t> shape,
2369  detail::any_container<ssize_t> strides) {
2370  return memoryview::from_buffer(
2371  const_cast<T *>(ptr), std::move(shape), std::move(strides), true);
2372  }
2373 
2386  static memoryview from_memory(void *mem, ssize_t size, bool readonly = false) {
2387  PyObject *ptr = PyMemoryView_FromMemory(
2388  reinterpret_cast<char *>(mem), size, (readonly) ? PyBUF_READ : PyBUF_WRITE);
2389  if (!ptr) {
2390  pybind11_fail("Could not allocate memoryview object!");
2391  }
2392  return memoryview(object(ptr, stolen_t{}));
2393  }
2394 
2395  static memoryview from_memory(const void *mem, ssize_t size) {
2396  return memoryview::from_memory(const_cast<void *>(mem), size, true);
2397  }
2398 
2399 #ifdef PYBIND11_HAS_STRING_VIEW
2400  static memoryview from_memory(std::string_view mem) {
2401  return from_memory(const_cast<char *>(mem.data()), static_cast<ssize_t>(mem.size()), true);
2402  }
2403 #endif
2404 };
2405 
2407 inline memoryview memoryview::from_buffer(void *ptr,
2408  ssize_t itemsize,
2409  const char *format,
2410  detail::any_container<ssize_t> shape,
2411  detail::any_container<ssize_t> strides,
2412  bool readonly) {
2413  size_t ndim = shape->size();
2414  if (ndim != strides->size()) {
2415  pybind11_fail("memoryview: shape length doesn't match strides length");
2416  }
2417  ssize_t size = ndim != 0u ? 1 : 0;
2418  for (size_t i = 0; i < ndim; ++i) {
2419  size *= (*shape)[i];
2420  }
2421  Py_buffer view;
2422  view.buf = ptr;
2423  view.obj = nullptr;
2424  view.len = size * itemsize;
2425  view.readonly = static_cast<int>(readonly);
2426  view.itemsize = itemsize;
2427  view.format = const_cast<char *>(format);
2428  view.ndim = static_cast<int>(ndim);
2429  view.shape = shape->data();
2430  view.strides = strides->data();
2431  view.suboffsets = nullptr;
2432  view.internal = nullptr;
2433  PyObject *obj = PyMemoryView_FromBuffer(&view);
2434  if (!obj) {
2435  throw error_already_set();
2436  }
2437  return memoryview(object(obj, stolen_t{}));
2438 }
2441 
2444 
2446 inline size_t len(handle h) {
2447  ssize_t result = PyObject_Length(h.ptr());
2448  if (result < 0) {
2449  throw error_already_set();
2450  }
2451  return (size_t) result;
2452 }
2453 
2456 inline size_t len_hint(handle h) {
2457  ssize_t result = PyObject_LengthHint(h.ptr(), 0);
2458  if (result < 0) {
2459  // Sometimes a length can't be determined at all (eg generators)
2460  // In which case simply return 0
2461  PyErr_Clear();
2462  return 0;
2463  }
2464  return (size_t) result;
2465 }
2466 
2467 inline str repr(handle h) {
2468  PyObject *str_value = PyObject_Repr(h.ptr());
2469  if (!str_value) {
2470  throw error_already_set();
2471  }
2472  return reinterpret_steal<str>(str_value);
2473 }
2474 
2475 inline iterator iter(handle obj) {
2476  PyObject *result = PyObject_GetIter(obj.ptr());
2477  if (!result) {
2478  throw error_already_set();
2479  }
2480  return reinterpret_steal<iterator>(result);
2481 }
2483 
2485 template <typename D>
2487  return iter(derived());
2488 }
2489 template <typename D>
2491  return iterator::sentinel();
2492 }
2493 template <typename D>
2495  return {derived(), reinterpret_borrow<object>(key)};
2496 }
2497 template <typename D>
2499  return {derived(), std::move(key)};
2500 }
2501 template <typename D>
2503  return {derived(), pybind11::str(key)};
2504 }
2505 template <typename D>
2507  return {derived(), reinterpret_borrow<object>(key)};
2508 }
2509 template <typename D>
2511  return {derived(), std::move(key)};
2512 }
2513 template <typename D>
2515  return {derived(), key};
2516 }
2517 template <typename D>
2519  return args_proxy(derived().ptr());
2520 }
2521 template <typename D>
2522 template <typename T>
2523 bool object_api<D>::contains(T &&item) const {
2524  return attr("__contains__")(std::forward<T>(item)).template cast<bool>();
2525 }
2526 
2527 template <typename D>
2529  return pybind11::str(derived());
2530 }
2531 
2532 template <typename D>
2534  return attr("__doc__");
2535 }
2536 
2537 template <typename D>
2539  return type::handle_of(derived());
2540 }
2541 
2542 template <typename D>
2544  int rv = PyObject_RichCompareBool(derived().ptr(), other.derived().ptr(), value);
2545  if (rv == -1) {
2546  throw error_already_set();
2547  }
2548  return rv == 1;
2549 }
2550 
2551 #define PYBIND11_MATH_OPERATOR_UNARY(op, fn) \
2552  template <typename D> \
2553  object object_api<D>::op() const { \
2554  object result = reinterpret_steal<object>(fn(derived().ptr())); \
2555  if (!result.ptr()) \
2556  throw error_already_set(); \
2557  return result; \
2558  }
2559 
2560 #define PYBIND11_MATH_OPERATOR_BINARY(op, fn) \
2561  template <typename D> \
2562  object object_api<D>::op(object_api const &other) const { \
2563  object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
2564  if (!result.ptr()) \
2565  throw error_already_set(); \
2566  return result; \
2567  }
2568 
2569 #define PYBIND11_MATH_OPERATOR_BINARY_INPLACE(iop, fn) \
2570  template <typename D> \
2571  object object_api<D>::iop(object_api const &other) { \
2572  object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
2573  if (!result.ptr()) \
2574  throw error_already_set(); \
2575  return result; \
2576  }
2577 
2578 PYBIND11_MATH_OPERATOR_UNARY(operator~, PyNumber_Invert)
2579 PYBIND11_MATH_OPERATOR_UNARY(operator-, PyNumber_Negative)
2580 PYBIND11_MATH_OPERATOR_BINARY(operator+, PyNumber_Add)
2581 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator+=, PyNumber_InPlaceAdd)
2582 PYBIND11_MATH_OPERATOR_BINARY(operator-, PyNumber_Subtract)
2583 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator-=, PyNumber_InPlaceSubtract)
2584 PYBIND11_MATH_OPERATOR_BINARY(operator*, PyNumber_Multiply)
2585 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator*=, PyNumber_InPlaceMultiply)
2586 PYBIND11_MATH_OPERATOR_BINARY(operator/, PyNumber_TrueDivide)
2587 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator/=, PyNumber_InPlaceTrueDivide)
2588 PYBIND11_MATH_OPERATOR_BINARY(operator|, PyNumber_Or)
2589 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator|=, PyNumber_InPlaceOr)
2590 PYBIND11_MATH_OPERATOR_BINARY(operator&, PyNumber_And)
2591 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator&=, PyNumber_InPlaceAnd)
2592 PYBIND11_MATH_OPERATOR_BINARY(operator^, PyNumber_Xor)
2593 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator^=, PyNumber_InPlaceXor)
2594 PYBIND11_MATH_OPERATOR_BINARY(operator<<, PyNumber_Lshift)
2595 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator<<=, PyNumber_InPlaceLshift)
2596 PYBIND11_MATH_OPERATOR_BINARY(operator>>, PyNumber_Rshift)
2597 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator>>=, PyNumber_InPlaceRshift)
2598 
2599 #undef PYBIND11_MATH_OPERATOR_UNARY
2600 #undef PYBIND11_MATH_OPERATOR_BINARY
2601 #undef PYBIND11_MATH_OPERATOR_BINARY_INPLACE
2602 
error_fetch_and_normalize::restore
void restore()
Definition: pytypes.h:705
generic_iterator::operator>
friend bool operator>(const It &a, const It &b)
Definition: pytypes.h:1237
sequence_fast_readonly::dereference
reference dereference() const
Definition: pytypes.h:1264
object_api::operator+=
object operator+=(object_api const &other)
PyNone_Check
bool PyNone_Check(PyObject *o)
Definition: pytypes.h:1345
int_
Definition: pytypes.h:1835
str_attr
Definition: pytypes.h:1087
slice::index_to_object
static object index_to_object(T index)
Definition: pytypes.h:1946
handle::check
bool check() const
Definition: pytypes.h:303
object_api::derived
const Derived & derived() const
Definition: pytypes.h:81
type::of
static type of(handle h)
Return a type object from a handle or an object.
Definition: pytypes.h:1533
error_already_set::error_already_set
error_already_set()
Definition: pytypes.h:743
format_descriptor
Definition: wrap/pybind11/include/pybind11/detail/common.h:1036
generic_iterator::difference_type
ssize_t difference_type
Definition: pytypes.h:1181
return_value_policy::move
@ move
str::str
str(const std::string &s)
Definition: pytypes.h:1586
setup.stderr
stderr
Definition: wrap/pybind11/setup.py:138
error_scope
RAII wrapper that temporarily clears any Python error state.
Definition: wrap/pybind11/include/pybind11/detail/common.h:1089
generic_iterator::operator-
friend It operator-(const It &a, difference_type n)
Definition: pytypes.h:1228
error_already_set::matches
bool matches(handle exc) const
Definition: pytypes.h:781
error_already_set::m_fetched_error
std::shared_ptr< detail::error_fetch_and_normalize > m_fetched_error
Definition: pytypes.h:788
bytearray::bytearray
bytearray()
Definition: pytypes.h:1768
dict_readonly::increment
void increment()
Definition: pytypes.h:1310
PYBIND11_OBJECT_CVT_DEFAULT
#define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun)
Definition: pytypes.h:1422
object_api::operator>>=
object operator>>=(object_api const &other)
list::end
detail::list_iterator end() const
Definition: pytypes.h:2185
object::object
object(const object &o)
Copy constructor; always increases the reference count.
Definition: pytypes.h:374
name
Annotation for function names.
Definition: attr.h:51
generic_iterator::operator<=
friend bool operator<=(const It &a, const It &b)
Definition: pytypes.h:1239
setattr
void setattr(handle obj, handle name, handle value)
Definition: pytypes.h:922
is_s_unpacking
std::is_same< args_proxy, T > is_s_unpacking
Definition: pytypes.h:1374
isinstance_generic
bool isinstance_generic(handle obj, const std::type_info &tp)
Definition: type_caster_base.h:495
sequence_item::set
static void set(handle obj, const IdxType &index, handle val)
Definition: pytypes.h:1124
generic_iterator::pointer
typename Policy::pointer pointer
Definition: pytypes.h:1185
dict::dict
dict(Args &&...args)
Definition: pytypes.h:2120
object_api::rich_compare
bool rich_compare(object_api const &other, int value) const
Definition: pytypes.h:2543
list::operator[]
detail::item_accessor operator[](T &&o) const
Definition: pytypes.h:2181
error_fetch_and_normalize::error_string
const std::string & error_string() const
Definition: pytypes.h:697
bytes
Definition: pytypes.h:1662
format
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:226
set
Definition: pytypes.h:2232
Eigen::internal::strides
EIGEN_ALWAYS_INLINE DSizes< IndexType, NumDims > strides(const DSizes< IndexType, NumDims > &dimensions)
Definition: TensorBlock.h:26
generic_iterator::iterator_category
typename Policy::iterator_category iterator_category
Definition: pytypes.h:1182
dict_readonly
Python's dictionary protocol permits this to be a forward iterator.
Definition: pytypes.h:1298
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
ssize_t
Py_ssize_t ssize_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:489
error_fetch_and_normalize::m_restore_called
bool m_restore_called
Definition: pytypes.h:726
PYBIND11_OBJECT
#define PYBIND11_OBJECT(Name, Parent, CheckFun)
Definition: pytypes.h:1431
function::is_cpp_function
bool is_cpp_function() const
Definition: pytypes.h:2262
error_already_set
Definition: pytypes.h:739
object::stolen_t
Definition: pytypes.h:438
generic_iterator::operator+=
It & operator+=(difference_type n)
Definition: pytypes.h:1214
type_info
Definition: internals.h:226
object_api::operator-=
object operator-=(object_api const &other)
kwargs
Definition: pytypes.h:2213
object_api::operator<<
object operator<<(object_api const &other) const
s
RealScalar s
Definition: level1_cplx_impl.h:126
sequence_slow_readwrite::increment
void increment()
Definition: pytypes.h:1286
list_accessor
accessor< accessor_policies::list_item > list_accessor
Definition: pytypes.h:67
object_api::is_none
bool is_none() const
Equivalent to obj is None in Python.
Definition: pytypes.h:149
tuple_item::key_type
size_t key_type
Definition: pytypes.h:1154
error_already_set::trace
const object & trace() const
Definition: pytypes.h:785
staticmethod
Definition: pytypes.h:2265
return_value_policy
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: wrap/pybind11/include/pybind11/detail/common.h:499
str_attr::get
static object get(handle obj, const char *key)
Definition: pytypes.h:1089
generic_item
Definition: pytypes.h:1093
sequence_fast_readonly::distance_to
ssize_t distance_to(const sequence_fast_readonly &b) const
Definition: pytypes.h:1269
list
Definition: pytypes.h:2166
generic_iterator::operator++
It & operator++()
Definition: pytypes.h:1196
bytes::bytes
bytes(const char *c="")
Definition: pytypes.h:1668
error_string
std::string error_string()
Definition: pytypes.h:729
str_attr::set
static void set(handle obj, const char *key, handle val)
Definition: pytypes.h:1090
object_api
Definition: pytypes.h:80
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
b
Scalar * b
Definition: benchVecAdd.cpp:17
str::format
str format(Args &&...args) const
Definition: pytypes.h:1632
PYBIND11_OBJECT_CVT
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun)
Definition: pytypes.h:1407
bytes::bytes
bytes(const char *c, const SzType &n)
Definition: pytypes.h:1675
dict_readonly::value_type
std::pair< handle, handle > value_type
Definition: pytypes.h:1301
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 > > is_pyobj_ptr_or_nullptr_t
Definition: pytypes.h:207
type::of
static type of()
Definition: pytypes.h:1546
literals
Definition: cast.h:1511
deferred_t
typename deferred_type< T, Us... >::type deferred_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:897
dict_readonly::equal
bool equal(const dict_readonly &b) const
Definition: pytypes.h:1315
handle::inc_ref
const handle & inc_ref() const &
Definition: pytypes.h:258
sequence_accessor
accessor< accessor_policies::sequence_item > sequence_accessor
Definition: pytypes.h:66
object_api::operator>=
bool operator>=(object_api const &other) const
Definition: pytypes.h:156
obj_attr
Definition: pytypes.h:1081
PYBIND11_STR_CHECK_FUN
#define PYBIND11_STR_CHECK_FUN
Definition: pytypes.h:1354
PYBIND11_WARNING_POP
PYBIND11_WARNING_PUSH PYBIND11_WARNING_POP
Definition: tensor.h:30
error_fetch_and_normalize::m_lazy_error_string
std::string m_lazy_error_string
Definition: pytypes.h:724
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
hasattr
bool hasattr(handle obj, handle name)
Definition: pytypes.h:870
PYBIND11_BYTES_FROM_STRING
#define PYBIND11_BYTES_FROM_STRING
Definition: wrap/pybind11/include/pybind11/detail/common.h:361
capsule
Definition: pytypes.h:1951
object_api::str
pybind11::str str() const
Definition: pytypes.h:2528
object_api::operator<
bool operator<(object_api const &other) const
Definition: pytypes.h:153
arrow_proxy
Quick proxy class needed to implement operator-> for iterators which can't return pointers.
Definition: pytypes.h:1245
generic_iterator::reference
typename Policy::reference reference
Definition: pytypes.h:1184
object_api::contains
bool contains(T &&item) const
Check if the given item is contained within this object, i.e. item in obj.
Definition: pytypes.h:2523
object_api::operator*=
object operator*=(object_api const &other)
object_api::operator&
object operator&(object_api const &other) const
type
Definition: pytypes.h:1525
dict::end
detail::dict_iterator end() const
Definition: pytypes.h:2125
slice::slice
slice(ssize_t start_, ssize_t stop_, ssize_t step_)
Definition: pytypes.h:1923
getattr
object getattr(handle obj, handle name)
Definition: pytypes.h:890
iterator::difference_type
ssize_t difference_type
Definition: pytypes.h:1463
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
handle::m_ptr
PyObject * m_ptr
Definition: pytypes.h:306
object_api::operator()
object operator()(Args &&...args) const
Definition: cast.h:1810
object_api::operator^=
object operator^=(object_api const &other)
error_fetch_and_normalize::m_trace
object m_trace
Definition: pytypes.h:720
detail
Definition: testSerializationNonlinear.cpp:70
generic_iterator::operator--
It operator--(int)
Definition: pytypes.h:1209
object_api::not_equal
bool not_equal(object_api const &other) const
Definition: pytypes.h:152
buffer
Definition: pytypes.h:2270
dict_getitemstring
PyObject * dict_getitemstring(PyObject *v, const char *key)
Definition: pytypes.h:960
sequence_slow_readwrite::iterator_category
std::random_access_iterator_tag iterator_category
Definition: pytypes.h:1278
memoryview::from_buffer
static memoryview from_buffer(const T *ptr, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides)
Definition: pytypes.h:2367
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
object_api::begin
iterator begin() const
Definition: pytypes.h:2486
iterator
Definition: pytypes.h:1460
memoryview::from_memory
static memoryview from_memory(const void *mem, ssize_t size)
Definition: pytypes.h:2395
h
const double h
Definition: testSimpleHelicopter.cpp:19
isinstance< handle >
bool isinstance< handle >(handle)=delete
sequence_slow_readwrite::index
ssize_t index
Definition: pytypes.h:1294
result
Values result
Definition: OdometryOptimize.cpp:8
error_already_set::restore
void restore()
Definition: pytypes.h:757
tuple::empty
bool empty() const
Definition: pytypes.h:2089
sequence_slow_readwrite::obj
handle obj
Definition: pytypes.h:1293
sequence_fast_readonly
Lightweight iterator policy using just a simple pointer: see PySequence_Fast_ITEMS
Definition: pytypes.h:1254
PYBIND11_FROM_STRING
#define PYBIND11_FROM_STRING
Definition: wrap/pybind11/include/pybind11/detail/common.h:373
object_api::operator/
object operator/(object_api const &other) const
weakref
Definition: pytypes.h:1892
object::PYBIND11_DEPRECATED
PYBIND11_DEPRECATED("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") object(handle h
PYBIND11_LONG_AS_LONGLONG
#define PYBIND11_LONG_AS_LONGLONG(o)
Definition: wrap/pybind11/include/pybind11/detail/common.h:367
hash
ssize_t hash(handle obj)
Definition: pytypes.h:934
as_unsigned
Unsigned as_unsigned(PyObject *o)
Definition: pytypes.h:1825
name
static char name[]
Definition: rgamma.c:72
generic_iterator::operator==
friend bool operator==(const It &a, const It &b)
Definition: pytypes.h:1234
list_item::key_type
size_t key_type
Definition: pytypes.h:1133
object_api::equal
bool equal(object_api const &other) const
Equivalent to obj == other in Python.
Definition: pytypes.h:151
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
sequence_fast_readonly::equal
bool equal(const sequence_fast_readonly &b) const
Definition: pytypes.h:1268
bool_
Definition: pytypes.h:1798
object_api::operator>
bool operator>(object_api const &other) const
Definition: pytypes.h:155
generic_iterator::operator-=
It & operator-=(difference_type n)
Definition: pytypes.h:1218
object::~object
~object()
Destructor; automatically calls handle::dec_ref()
Definition: pytypes.h:378
n
int n
Definition: BiCGSTAB_simple.cpp:1
bool_::raw_bool
static PyObject * raw_bool(PyObject *op)
Return the truth value of an object – always returns a new reference.
Definition: pytypes.h:1810
view
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set view
Definition: gnuplot_common_settings.hh:27
slice
Definition: pytypes.h:1909
object
Definition: pytypes.h:364
error_fetch_and_normalize::m_lazy_error_string_completed
bool m_lazy_error_string_completed
Definition: pytypes.h:725
error_already_set::value
const object & value() const
Definition: pytypes.h:784
generic_item::get
static object get(handle obj, handle key)
Definition: pytypes.h:1096
doc
Annotation for documentation.
Definition: attr.h:45
list::size
size_t size() const
Definition: pytypes.h:2177
error_already_set::discard_as_unraisable
void discard_as_unraisable(const char *err_context)
Definition: pytypes.h:770
generic_iterator
STL iterator template used for tuple, list, sequence and dict.
Definition: pytypes.h:1177
tuple::begin
detail::tuple_iterator begin() const
Definition: pytypes.h:2095
generic_iterator::operator>=
friend bool operator>=(const It &a, const It &b)
Definition: pytypes.h:1238
sequence::empty
bool empty() const
Definition: pytypes.h:2156
PYBIND11_LONG_CHECK
#define PYBIND11_LONG_CHECK(o)
Definition: wrap/pybind11/include/pybind11/detail/common.h:366
sequence_slow_readwrite::decrement
void decrement()
Definition: pytypes.h:1287
list_item::set
static void set(handle obj, const IdxType &index, handle val)
Definition: pytypes.h:1145
dict
Definition: pytypes.h:2107
dict_readonly::reference
const value_type reference
Definition: pytypes.h:1302
raise_from
void raise_from(PyObject *type, const char *message)
Definition: pytypes.h:797
object_api::operator|=
object operator|=(object_api const &other)
isinstance
bool isinstance(handle obj)
Definition: pytypes.h:842
data
int data[]
Definition: Map_placement_new.cpp:1
sequence_fast_readonly::increment
void increment()
Definition: pytypes.h:1265
bytearray::bytearray
bytearray(const char *c, const SzType &n)
Definition: pytypes.h:1761
sequence::begin
detail::sequence_iterator begin() const
Definition: pytypes.h:2162
handle
Definition: pytypes.h:226
generic_iterator::generic_iterator
generic_iterator(handle seq, ssize_t index)
Definition: pytypes.h:1188
arrow_proxy::value
T value
Definition: pytypes.h:1246
sequence
Definition: pytypes.h:2146
sequence_item::key_type
size_t key_type
Definition: pytypes.h:1112
handle::cast
T cast() const
Definition: cast.h:1234
tuple_accessor
accessor< accessor_policies::tuple_item > tuple_accessor
Definition: pytypes.h:68
tuple::operator[]
detail::item_accessor operator[](T &&o) const
Definition: pytypes.h:2092
type::handle_of
static handle handle_of()
Definition: cast.h:1828
reinterpret_borrow
T reinterpret_borrow(handle h)
Definition: pytypes.h:467
delattr
void delattr(handle obj, handle name)
Definition: pytypes.h:878
arg_v
Definition: cast.h:1439
error_fetch_and_normalize::error_fetch_and_normalize
error_fetch_and_normalize(const char *called)
Definition: pytypes.h:514
iterator::iterator_category
std::input_iterator_tag iterator_category
Definition: pytypes.h:1462
sequence_fast_readonly::decrement
void decrement()
Definition: pytypes.h:1266
object_api::operator<<=
object operator<<=(object_api const &other)
error_fetch_and_normalize
Definition: pytypes.h:504
PyStaticMethod_Check
bool PyStaticMethod_Check(PyObject *o)
Definition: pytypes.h:1357
return_value_policy::copy
@ copy
args_are_all_keyword_or_ds
constexpr bool args_are_all_keyword_or_ds()
Definition: pytypes.h:2103
args_proxy::operator*
kwargs_proxy operator*() const
Definition: pytypes.h:1367
handle::inc_ref_counter
static std::size_t inc_ref_counter(std::size_t add)
Definition: pytypes.h:335
object::object
object()=default
PYBIND11_EXPORT_EXCEPTION
#define PYBIND11_EXPORT_EXCEPTION
Definition: wrap/pybind11/include/pybind11/detail/common.h:171
object::release
handle release()
Definition: pytypes.h:385
error_fetch_and_normalize::m_type
object m_type
Definition: pytypes.h:720
list_item
Definition: pytypes.h:1132
memoryview::from_buffer
static memoryview from_buffer(const void *ptr, ssize_t itemsize, const char *format, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides)
Definition: pytypes.h:2344
memoryview::from_buffer
static memoryview from_buffer(T *ptr, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides, bool readonly=false)
Definition: pytypes.h:2354
dict::clear
void clear()
Definition: pytypes.h:2126
get_function
handle get_function(handle value)
Definition: pytypes.h:945
str::str
str(const char *c="")
Definition: pytypes.h:1576
generic_iterator::operator--
It & operator--()
Definition: pytypes.h:1205
handle::handle
handle(T ptr)
Definition: pytypes.h:236
add
graph add(PriorFactor< Pose2 >(1, priorMean, priorNoise))
arg
Definition: cast.h:1412
iterator::operator!=
friend bool operator!=(const iterator &a, const iterator &b)
Definition: pytypes.h:1511
anyset::contains
bool contains(T &&val) const
Definition: pytypes.h:2223
list::insert
void insert(const IdxType &index, ValType &&val)
Definition: pytypes.h:2195
object_api::operator>>
object operator>>(object_api const &other) const
object_api::get_type
handle get_type() const
Definition: pytypes.h:2538
slice::compute
bool compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const
Definition: pytypes.h:1928
negation
Definition: wrap/pybind11/include/pybind11/detail/common.h:713
gtsam::utils.visual_isam.step
def step(data, isam, result, truth, currPoseIndex, isamArgs=())
Definition: visual_isam.py:82
sequence_slow_readwrite::sequence_slow_readwrite
sequence_slow_readwrite(handle obj, ssize_t index)
Definition: pytypes.h:1283
arrow_proxy::arrow_proxy
arrow_proxy(T &&value) noexcept
Definition: pytypes.h:1249
info
else if n * info
Definition: 3rdparty/Eigen/lapack/cholesky.cpp:18
generic_iterator::operator<
friend bool operator<(const It &a, const It &b)
Definition: pytypes.h:1236
bytearray
Definition: pytypes.h:1756
object_or_cast
auto object_or_cast(T &&o) -> decltype(std::forward< T >(o))
Definition: pytypes.h:1004
dict::size
size_t size() const
Definition: pytypes.h:2122
object::borrowed_t
Definition: pytypes.h:437
dict_getitemstringref
PyObject * dict_getitemstringref(PyObject *v, const char *key)
Definition: pytypes.h:983
object_api::operator~
object operator~() const
memoryview
Definition: pytypes.h:2288
sequence::operator[]
detail::item_accessor operator[](T &&o) const
Definition: pytypes.h:2159
is_ds_unpacking
std::is_same< kwargs_proxy, T > is_ds_unpacking
Definition: pytypes.h:1376
PYBIND11_NAMESPACE
Definition: test_custom_type_casters.cpp:24
object_api::is
bool is(object_api const &other) const
Equivalent to obj is other in Python.
Definition: pytypes.h:147
Eigen::Triplet
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:162
int_::int_
int_(T value)
Definition: pytypes.h:1842
cpp_function
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
Definition: pybind11.h:125
common.h
args_proxy::args_proxy
args_proxy(handle h)
Definition: pytypes.h:1366
handle::inc_ref_counter
static std::size_t inc_ref_counter()
Definition: pytypes.h:342
dict_getitem
PyObject * dict_getitem(PyObject *v, PyObject *key)
Definition: pytypes.h:975
pybind11_fail
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
Definition: wrap/pybind11/include/pybind11/detail/common.h:1026
str::str
str(const char *c, const SzType &n)
Definition: pytypes.h:1563
simple_collector
Definition: cast.h:1633
kwargs_proxy
Definition: pytypes.h:1359
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
bool_::bool_
bool_(bool value)
Definition: pytypes.h:1804
buffer_info.h
set::add
bool add(T &&val)
Definition: pytypes.h:2241
set_error
void set_error(const handle &type, const char *message)
Definition: pytypes.h:346
bytearray::size
size_t size() const
Definition: pytypes.h:1772
tuple::operator[]
detail::tuple_accessor operator[](size_t index) const
Definition: pytypes.h:2090
object::object
object(object &&other) noexcept
Move constructor; steals the object from other and preserves its reference count.
Definition: pytypes.h:376
generic_iterator::operator->
pointer operator->() const
Definition: pytypes.h:1194
PYBIND11_INPLACE_OP
#define PYBIND11_INPLACE_OP(iop)
Definition: pytypes.h:414
PYBIND11_MATH_OPERATOR_UNARY
#define PYBIND11_MATH_OPERATOR_UNARY(op, fn)
Definition: pytypes.h:2551
is_keyword
std::is_base_of< arg, T > is_keyword
Python argument categories (using PEP 448 terms)
Definition: pytypes.h:1372
tuple_item::set
static void set(handle obj, const IdxType &index, handle val)
Definition: pytypes.h:1166
str
Definition: pytypes.h:1558
key
const gtsam::Symbol key('X', 0)
set
void set(Container &c, Position position, const Value &value)
Definition: stdlist_overload.cpp:37
bytearray::bytearray
bytearray(const std::string &s)
Definition: pytypes.h:1770
dict_readonly::obj
handle obj
Definition: pytypes.h:1318
object::operator=
object & operator=(object &&other) noexcept
Definition: pytypes.h:404
tuple_item
Definition: pytypes.h:1153
unpacking_collector
Helper class which collects positional, keyword, * and ** arguments for a Python function call.
Definition: cast.h:1659
handle::handle
handle(T &obj)
Enable implicit conversion through T::operator PyObject *().
Definition: pytypes.h:247
set::clear
void clear()
Definition: pytypes.h:2244
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
isinstance< object >
bool isinstance< object >(handle obj)
Definition: pytypes.h:854
PYBIND11_OBJECT_DEFAULT
#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun)
Definition: pytypes.h:1445
object_api::operator-
object operator-() const
tuple_iterator
generic_iterator< iterator_policies::sequence_fast_readonly > tuple_iterator
Definition: pytypes.h:1325
accessor
Definition: pytypes.h:53
tuple::end
detail::tuple_iterator end() const
Definition: pytypes.h:2096
iterator::operator->
pointer operator->() const
Definition: pytypes.h:1490
object_api::operator/=
object operator/=(object_api const &other)
generic_iterator::operator++
It operator++(int)
Definition: pytypes.h:1200
dict_readonly::iterator_category
std::forward_iterator_tag iterator_category
Definition: pytypes.h:1300
sequence_slow_readwrite::advance
void advance(ssize_t n)
Definition: pytypes.h:1288
dict::contains
bool contains(T &&key) const
Definition: pytypes.h:2128
handle::ptr
PyObject * ptr() const
Return the underlying PyObject * pointer.
Definition: pytypes.h:250
tuple::size
size_t size() const
Definition: pytypes.h:2088
tuple_item::get
static object get(handle obj, const IdxType &index)
Definition: pytypes.h:1157
iterator::advance
void advance()
Definition: pytypes.h:1514
generic_iterator::operator+
friend It operator+(difference_type n, const It &b)
Definition: pytypes.h:1227
memoryview::from_buffer
static memoryview from_buffer(void *ptr, ssize_t itemsize, const char *format, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides, bool readonly=false)
dict_readonly::dict_readonly
dict_readonly(handle obj, ssize_t pos)
Definition: pytypes.h:1306
sequence_fast_readonly::iterator_category
std::random_access_iterator_tag iterator_category
Definition: pytypes.h:1256
iterator::operator==
friend bool operator==(const iterator &a, const iterator &b)
Definition: pytypes.h:1510
error_already_set::type
const object & type() const
Definition: pytypes.h:783
sequence_item
Definition: pytypes.h:1111
arrow_proxy::operator->
T * operator->() const
Definition: pytypes.h:1250
PYBIND11_WARNING_DISABLE_MSVC
PYBIND11_WARNING_PUSH PYBIND11_WARNING_DISABLE_MSVC(5054) PYBIND11_WARNING_POP static_assert(EIGEN_VERSION_AT_LEAST(3
sequence::operator[]
detail::sequence_accessor operator[](size_t index) const
Definition: pytypes.h:2157
handle::handle
handle()=default
The default constructor creates a handle with a nullptr-valued pointer.
ssize_t_cast
ssize_t ssize_t_cast(const IntType &val)
Definition: wrap/pybind11/include/pybind11/detail/common.h:493
dict::empty
bool empty() const
Definition: pytypes.h:2123
obj_attr::get
static object get(handle obj, handle key)
Definition: pytypes.h:1083
iter
iterator iter(handle obj)
Definition: pytypes.h:2475
iterable
Definition: pytypes.h:1551
list::list
list(SzType size=0)
Definition: pytypes.h:2172
object::object
object(handle h, borrowed_t)
Definition: pytypes.h:449
float_::float_
float_(double value=.0)
Definition: pytypes.h:1881
handle::throw_gilstate_error
void throw_gilstate_error(const std::string &function_name) const
Definition: pytypes.h:310
str::str
str(handle h)
Definition: pytypes.h:1608
std
Definition: BFloat16.h:88
item_accessor
accessor< accessor_policies::generic_item > item_accessor
Definition: pytypes.h:65
dict::begin
detail::dict_iterator begin() const
Definition: pytypes.h:2124
args
Definition: pytypes.h:2210
error_fetch_and_normalize::format_value_and_trace
std::string format_value_and_trace() const
Definition: pytypes.h:574
buffer_info
Information record describing a Python buffer object.
Definition: buffer_info.h:46
Eigen::array::size
EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE std::size_t size()
Definition: EmulateArray.h:44
args_proxy
Definition: pytypes.h:1364
sequence_fast_readonly::sequence_fast_readonly
sequence_fast_readonly(handle obj, ssize_t n)
Definition: pytypes.h:1261
sequence_item::get
static object get(handle obj, const IdxType &index)
Definition: pytypes.h:1115
generic_iterator::value_type
typename Policy::value_type value_type
Definition: pytypes.h:1183
sequence_slow_readwrite
Full read and write access using the sequence protocol: see detail::sequence_accessor
Definition: pytypes.h:1276
str_attr::key_type
const char * key_type
Definition: pytypes.h:1088
tuple
Definition: pytypes.h:2077
generic_iterator::operator*
reference operator*() const
Definition: pytypes.h:1191
is_pyobject
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
Definition: pytypes.h:73
list::operator[]
detail::list_accessor operator[](size_t index) const
Definition: pytypes.h:2179
memoryview::from_memory
static memoryview from_memory(void *mem, ssize_t size, bool readonly=false)
Definition: pytypes.h:2386
object_api::doc
str_attr_accessor doc() const
Get or set the object's docstring, i.e. obj.__doc__.
Definition: pytypes.h:2533
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
float_
Definition: pytypes.h:1870
handle::dec_ref
const handle & dec_ref() const &
Definition: pytypes.h:276
object::object
object(handle h, stolen_t)
Definition: pytypes.h:450
list::append
void append(T &&val)
Definition: pytypes.h:2187
object_api::operator<=
bool operator<=(object_api const &other) const
Definition: pytypes.h:154
iterator::operator++
iterator operator++(int)
Definition: pytypes.h:1475
list_iterator
generic_iterator< iterator_policies::sequence_fast_readonly > list_iterator
Definition: pytypes.h:1326
PyIterable_Check
bool PyIterable_Check(PyObject *obj)
Definition: pytypes.h:1335
sequence_slow_readwrite::equal
bool equal(const sequence_slow_readwrite &b) const
Definition: pytypes.h:1289
object_api::operator&=
object operator&=(object_api const &other)
str::raw_str
static PyObject * raw_str(PyObject *op)
Return string representation – always returns a new reference, even if already a str.
Definition: pytypes.h:1638
accessor_policies
Definition: pytypes.h:54
PYBIND11_MATH_OPERATOR_BINARY
#define PYBIND11_MATH_OPERATOR_BINARY(op, fn)
Definition: pytypes.h:2560
object_api::operator[]
item_accessor operator[](handle key) const
Definition: pytypes.h:2494
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
function
Definition: pytypes.h:2252
gtsam.examples.DogLegOptimizerExample.float
float
Definition: DogLegOptimizerExample.py:113
generic_item::set
static void set(handle obj, handle key, handle val)
Definition: pytypes.h:1104
PYBIND11_MATH_OPERATOR_BINARY_INPLACE
#define PYBIND11_MATH_OPERATOR_BINARY_INPLACE(iop, fn)
Definition: pytypes.h:2569
object_api::attr
obj_attr_accessor attr(handle key) const
Definition: pytypes.h:2506
error_already_set::discard_as_unraisable
void discard_as_unraisable(object err_context)
Definition: pytypes.h:763
object::operator=
object & operator=(const object &other)
Definition: pytypes.h:391
len_hint
size_t len_hint(handle h)
Definition: pytypes.h:2456
weakref::raw_weakref
static PyObject * raw_weakref(PyObject *o)
Definition: pytypes.h:1906
len
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2446
dict::raw_dict
static PyObject * raw_dict(PyObject *op)
Call the dict Python type – always returns a new reference.
Definition: pytypes.h:2138
PYBIND11_DEPRECATED
PYBIND11_DEPRECATED("make_simple_namespace should be replaced with " "py::module_::import(\"types\").attr(\"SimpleNamespace\") ") object make_simple_namespace(Args &&...args_)
Definition: pybind11.h:1384
object::cast
T cast() const &
Definition: cast.h:1293
handle::ptr
PyObject *& ptr()
Definition: pytypes.h:251
bytes::string_op
T string_op() const
Definition: pytypes.h:1705
object_api::operator|
object operator|(object_api const &other) const
none
Definition: pytypes.h:1786
pyobject_tag
Tag and check to identify a class which implements the Python object API.
Definition: pytypes.h:71
object_api::operator+
object operator+(object_api const &other) const
pos
Definition: example-NearestNeighbor.cpp:32
anyset::empty
bool empty() const
Definition: pytypes.h:2221
gtsam.examples.DogLegOptimizerExample.default
default
Definition: DogLegOptimizerExample.py:111
error_fetch_and_normalize::matches
bool matches(handle exc) const
Definition: pytypes.h:715
sequence_iterator
generic_iterator< iterator_policies::sequence_slow_readwrite > sequence_iterator
Definition: pytypes.h:1332
sequence_fast_readonly::ptr
PyObject ** ptr
Definition: pytypes.h:1272
PYBIND11_BYTES_FROM_STRING_AND_SIZE
#define PYBIND11_BYTES_FROM_STRING_AND_SIZE
Definition: wrap/pybind11/include/pybind11/detail/common.h:362
generic_iterator::operator!=
friend bool operator!=(const It &a, const It &b)
Definition: pytypes.h:1235
frozenset
Definition: pytypes.h:2247
object_api::operator^
object operator^(object_api const &other) const
object_api::ref_count
ssize_t ref_count() const
Return the object's current reference count.
Definition: pytypes.h:186
return_value_policy::automatic_reference
@ automatic_reference
dict_readonly::dereference
reference dereference() const
Definition: pytypes.h:1309
reinterpret_steal
T reinterpret_steal(handle h)
Definition: pytypes.h:480
object_api::operator*
args_proxy operator*() const
Definition: pytypes.h:2518
dict_iterator
generic_iterator< iterator_policies::dict_readonly > dict_iterator
Definition: pytypes.h:1333
kwargs_proxy::kwargs_proxy
kwargs_proxy(handle h)
Definition: pytypes.h:1361
list::empty
bool empty() const
Definition: pytypes.h:2178
PyEllipsis_Check
bool PyEllipsis_Check(PyObject *o)
Definition: pytypes.h:1346
gtsam.examples.ShonanAveragingCLI.str
str
Definition: ShonanAveragingCLI.py:115
PYBIND11_SLICE_OBJECT
#define PYBIND11_SLICE_OBJECT
Definition: wrap/pybind11/include/pybind11/detail/common.h:372
Eigen::seq
internal::enable_if<!(symbolic::is_symbolic< FirstType >::value||symbolic::is_symbolic< LastType >::value), ArithmeticSequence< typename internal::cleanup_index_type< FirstType >::type, Index > >::type seq(FirstType f, LastType l)
Definition: ArithmeticSequence.h:234
PYBIND11_BYTES_CHECK
#define PYBIND11_BYTES_CHECK
Definition: wrap/pybind11/include/pybind11/detail/common.h:360
get
Container::iterator get(Container &c, Position position)
Definition: stdlist_overload.cpp:29
slice::compute
bool compute(ssize_t length, ssize_t *start, ssize_t *stop, ssize_t *step, ssize_t *slicelength) const
Definition: pytypes.h:1937
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: wrap/pybind11/include/pybind11/detail/common.h:654
list_item::get
static object get(handle obj, const IdxType &index)
Definition: pytypes.h:1136
generic_iterator::operator[]
reference operator[](difference_type n) const
Definition: pytypes.h:1193
generic_iterator::operator-
friend difference_type operator-(const It &a, const It &b)
Definition: pytypes.h:1232
sequence_slow_readwrite::distance_to
ssize_t distance_to(const sequence_slow_readwrite &b) const
Definition: pytypes.h:1290
test_callbacks.value
value
Definition: test_callbacks.py:160
error_fetch_and_normalize::m_value
object m_value
Definition: pytypes.h:720
object::is_borrowed
bool is_borrowed
Definition: pytypes.h:370
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
obj_class_name
const char * obj_class_name(PyObject *obj)
Definition: pytypes.h:487
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
generic_iterator::operator+
friend It operator+(const It &a, difference_type n)
Definition: pytypes.h:1223
sequence_slow_readwrite::dereference
reference dereference() const
Definition: pytypes.h:1285
Eigen::internal::cast
EIGEN_DEVICE_FUNC NewType cast(const OldType &x)
Definition: Eigen/src/Core/MathFunctions.h:460
iterator::operator*
reference operator*() const
Definition: pytypes.h:1482
object_api::PYBIND11_DEPRECATED
PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)") object call(Args &&...args) const
operator*
Vector3_ operator*(const Double_ &s, const Vector3_ &v)
Definition: InverseKinematicsExampleExpressions.cpp:42
obj_attr::set
static void set(handle obj, handle key, handle val)
Definition: pytypes.h:1084
iterator::sentinel
static iterator sentinel()
Definition: pytypes.h:1508
ellipsis
Definition: pytypes.h:1792
sequence_fast_readonly::advance
void advance(ssize_t n)
Definition: pytypes.h:1267
bytes::bytes
bytes(const std::string &s)
Definition: pytypes.h:1684
object_api::end
iterator end() const
Return a sentinel which ends iteration.
Definition: pytypes.h:2490
sequence::end
detail::sequence_iterator end() const
Definition: pytypes.h:2163
list::clear
void clear()
Definition: pytypes.h:2203
pybind11.msg
msg
Definition: wrap/pybind11/pybind11/__init__.py:6
anyset
Definition: pytypes.h:2217
repr
str repr(handle h)
Definition: pytypes.h:2467
list::begin
detail::list_iterator begin() const
Definition: pytypes.h:2184


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:02:44