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  sequence_fast_readonly() = default;
1263 
1264  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1265  reference dereference() const { return *ptr; }
1266  void increment() { ++ptr; }
1267  void decrement() { --ptr; }
1268  void advance(ssize_t n) { ptr += n; }
1269  bool equal(const sequence_fast_readonly &b) const { return ptr == b.ptr; }
1270  ssize_t distance_to(const sequence_fast_readonly &b) const { return ptr - b.ptr; }
1271 
1272 private:
1273  PyObject **ptr;
1274 };
1275 
1278 protected:
1279  using iterator_category = std::random_access_iterator_tag;
1283 
1284  sequence_slow_readwrite(handle obj, ssize_t index) : obj(obj), index(index) {}
1285  sequence_slow_readwrite() = default;
1286 
1287  reference dereference() const { return {obj, static_cast<size_t>(index)}; }
1288  void increment() { ++index; }
1289  void decrement() { --index; }
1290  void advance(ssize_t n) { index += n; }
1291  bool equal(const sequence_slow_readwrite &b) const { return index == b.index; }
1292  ssize_t distance_to(const sequence_slow_readwrite &b) const { return index - b.index; }
1293 
1294 private:
1297 };
1298 
1301 protected:
1302  using iterator_category = std::forward_iterator_tag;
1303  using value_type = std::pair<handle, handle>;
1304  using reference = const value_type; // PR #3263
1306 
1307  dict_readonly() = default;
1308  dict_readonly(handle obj, ssize_t pos) : obj(obj), pos(pos) { increment(); }
1309 
1310  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1311  reference dereference() const { return {key, value}; }
1312  void increment() {
1313  if (PyDict_Next(obj.ptr(), &pos, &key, &value) == 0) {
1314  pos = -1;
1315  }
1316  }
1317  bool equal(const dict_readonly &b) const { return pos == b.pos; }
1318 
1319 private:
1321  PyObject *key = nullptr, *value = nullptr;
1322  ssize_t pos = -1;
1323 };
1324 PYBIND11_NAMESPACE_END(iterator_policies)
1325 
1326 #if !defined(PYPY_VERSION)
1329 #else
1332 #endif
1333 
1336 
1337 inline bool PyIterable_Check(PyObject *obj) {
1338  PyObject *iter = PyObject_GetIter(obj);
1339  if (iter) {
1340  Py_DECREF(iter);
1341  return true;
1342  }
1343  PyErr_Clear();
1344  return false;
1345 }
1346 
1347 inline bool PyNone_Check(PyObject *o) { return o == Py_None; }
1348 inline bool PyEllipsis_Check(PyObject *o) { return o == Py_Ellipsis; }
1349 
1350 #ifdef PYBIND11_STR_LEGACY_PERMISSIVE
1351 inline bool PyUnicode_Check_Permissive(PyObject *o) {
1352  return PyUnicode_Check(o) || PYBIND11_BYTES_CHECK(o);
1353 }
1354 # define PYBIND11_STR_CHECK_FUN detail::PyUnicode_Check_Permissive
1355 #else
1356 # define PYBIND11_STR_CHECK_FUN PyUnicode_Check
1357 #endif
1358 
1359 inline bool PyStaticMethod_Check(PyObject *o) { return o->ob_type == &PyStaticMethod_Type; }
1360 
1361 class kwargs_proxy : public handle {
1362 public:
1363  explicit kwargs_proxy(handle h) : handle(h) {}
1364 };
1365 
1366 class args_proxy : public handle {
1367 public:
1368  explicit args_proxy(handle h) : handle(h) {}
1369  kwargs_proxy operator*() const { return kwargs_proxy(*this); }
1370 };
1371 
1373 template <typename T>
1374 using is_keyword = std::is_base_of<arg, T>;
1375 template <typename T>
1376 using is_s_unpacking = std::is_same<args_proxy, T>; // * unpacking
1377 template <typename T>
1378 using is_ds_unpacking = std::is_same<kwargs_proxy, T>; // ** unpacking
1379 template <typename T>
1381 template <typename T>
1383 
1384 // Call argument collector forward declarations
1385 template <return_value_policy policy = return_value_policy::automatic_reference>
1386 class simple_collector;
1387 template <return_value_policy policy = return_value_policy::automatic_reference>
1388 class unpacking_collector;
1389 
1391 
1392 // TODO: After the deprecated constructors are removed, this macro can be simplified by
1393 // inheriting ctors: `using Parent::Parent`. It's not an option right now because
1394 // the `using` statement triggers the parent deprecation warning even if the ctor
1395 // isn't even used.
1396 #define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
1397 public: \
1398  PYBIND11_DEPRECATED("Use reinterpret_borrow<" #Name ">() or reinterpret_steal<" #Name ">()") \
1399  Name(handle h, bool is_borrowed) \
1400  : Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) {} \
1401  Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) {} \
1402  Name(handle h, stolen_t) : Parent(h, stolen_t{}) {} \
1403  PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \
1404  bool check() const { return m_ptr != nullptr && (CheckFun(m_ptr) != 0); } \
1405  static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \
1406  template <typename Policy_> /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1407  Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) {}
1408 
1409 #define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \
1410  PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
1411  /* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
1412  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1413  Name(const object &o) \
1414  : Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
1415  if (!m_ptr) \
1416  throw ::pybind11::error_already_set(); \
1417  } \
1418  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1419  Name(object &&o) : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
1420  if (!m_ptr) \
1421  throw ::pybind11::error_already_set(); \
1422  }
1423 
1424 #define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun) \
1425  PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \
1426  Name() = default;
1427 
1428 #define PYBIND11_OBJECT_CHECK_FAILED(Name, o_ptr) \
1429  ::pybind11::type_error("Object of type '" \
1430  + ::pybind11::detail::get_fully_qualified_tp_name(Py_TYPE(o_ptr)) \
1431  + "' is not an instance of '" #Name "'")
1432 
1433 #define PYBIND11_OBJECT(Name, Parent, CheckFun) \
1434  PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
1435  /* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
1436  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1437  Name(const object &o) : Parent(o) { \
1438  if (m_ptr && !check_(m_ptr)) \
1439  throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
1440  } \
1441  /* NOLINTNEXTLINE(google-explicit-constructor) */ \
1442  Name(object &&o) : Parent(std::move(o)) { \
1443  if (m_ptr && !check_(m_ptr)) \
1444  throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
1445  }
1446 
1447 #define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun) \
1448  PYBIND11_OBJECT(Name, Parent, CheckFun) \
1449  Name() = default;
1450 
1453 
1462 class iterator : public object {
1463 public:
1464  using iterator_category = std::input_iterator_tag;
1467  using reference = const handle; // PR #3263
1468  using pointer = const handle *;
1469 
1470  PYBIND11_OBJECT_DEFAULT(iterator, object, PyIter_Check)
1471 
1472  iterator &operator++() {
1473  advance();
1474  return *this;
1475  }
1476 
1478  auto rv = *this;
1479  advance();
1480  return rv;
1481  }
1482 
1483  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1485  if (m_ptr && !value.ptr()) {
1486  auto &self = const_cast<iterator &>(*this);
1487  self.advance();
1488  }
1489  return value;
1490  }
1491 
1493  operator*();
1494  return &value;
1495  }
1496 
1510  static iterator sentinel() { return {}; }
1511 
1512  friend bool operator==(const iterator &a, const iterator &b) { return a->ptr() == b->ptr(); }
1513  friend bool operator!=(const iterator &a, const iterator &b) { return a->ptr() != b->ptr(); }
1514 
1515 private:
1516  void advance() {
1517  value = reinterpret_steal<object>(PyIter_Next(m_ptr));
1518  if (value.ptr() == nullptr && PyErr_Occurred()) {
1519  throw error_already_set();
1520  }
1521  }
1522 
1523 private:
1524  object value = {};
1525 };
1526 
1527 class type : public object {
1528 public:
1529  PYBIND11_OBJECT(type, object, PyType_Check)
1530 
1531 
1532  static handle handle_of(handle h) { return handle((PyObject *) Py_TYPE(h.ptr())); }
1533 
1535  static type of(handle h) { return type(type::handle_of(h), borrowed_t{}); }
1536 
1537  // Defined in pybind11/cast.h
1541  template <typename T>
1542  static handle handle_of();
1543 
1547  template <typename T>
1548  static type of() {
1549  return type(type::handle_of<T>(), borrowed_t{});
1550  }
1551 };
1552 
1553 class iterable : public object {
1554 public:
1556 };
1557 
1558 class bytes;
1559 
1560 class str : public object {
1561 public:
1563 
1565  str(const char *c, const SzType &n)
1566  : object(PyUnicode_FromStringAndSize(c, ssize_t_cast(n)), stolen_t{}) {
1567  if (!m_ptr) {
1568  if (PyErr_Occurred()) {
1569  throw error_already_set();
1570  }
1571  pybind11_fail("Could not allocate string object!");
1572  }
1573  }
1574 
1575  // 'explicit' is explicitly omitted from the following constructors to allow implicit
1576  // conversion to py::str from C++ string-like objects
1577  // NOLINTNEXTLINE(google-explicit-constructor)
1578  str(const char *c = "") : object(PyUnicode_FromString(c), stolen_t{}) {
1579  if (!m_ptr) {
1580  if (PyErr_Occurred()) {
1581  throw error_already_set();
1582  }
1583  pybind11_fail("Could not allocate string object!");
1584  }
1585  }
1586 
1587  // NOLINTNEXTLINE(google-explicit-constructor)
1588  str(const std::string &s) : str(s.data(), s.size()) {}
1589 
1590 #ifdef PYBIND11_HAS_STRING_VIEW
1591  // enable_if is needed to avoid "ambiguous conversion" errors (see PR #3521).
1593  // NOLINTNEXTLINE(google-explicit-constructor)
1594  str(T s) : str(s.data(), s.size()) {}
1595 
1596 # ifdef PYBIND11_HAS_U8STRING
1597  // reinterpret_cast here is safe (C++20 guarantees char8_t has the same size/alignment as char)
1598  // NOLINTNEXTLINE(google-explicit-constructor)
1599  str(std::u8string_view s) : str(reinterpret_cast<const char *>(s.data()), s.size()) {}
1600 # endif
1601 
1602 #endif
1603 
1604  explicit str(const bytes &b);
1605 
1610  explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) {
1611  if (!m_ptr) {
1612  throw error_already_set();
1613  }
1614  }
1615 
1616  // NOLINTNEXTLINE(google-explicit-constructor)
1617  operator std::string() const {
1618  object temp = *this;
1619  if (PyUnicode_Check(m_ptr)) {
1620  temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(m_ptr));
1621  if (!temp) {
1622  throw error_already_set();
1623  }
1624  }
1625  char *buffer = nullptr;
1626  ssize_t length = 0;
1627  if (PyBytes_AsStringAndSize(temp.ptr(), &buffer, &length) != 0) {
1628  throw error_already_set();
1629  }
1630  return std::string(buffer, (size_t) length);
1631  }
1632 
1633  template <typename... Args>
1634  str format(Args &&...args) const {
1635  return attr("format")(std::forward<Args>(args)...);
1636  }
1637 
1638 private:
1640  static PyObject *raw_str(PyObject *op) {
1641  PyObject *str_value = PyObject_Str(op);
1642  return str_value;
1643  }
1644 };
1646 
1647 inline namespace literals {
1651 inline str
1652 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5
1653 operator"" _s // gcc 4.8.5 insists on having a space (hard error).
1654 #else
1655 operator""_s // clang 17 generates a deprecation warning if there is a space.
1656 #endif
1657  (const char *s, size_t size) {
1658  return {s, size};
1659 }
1660 } // namespace literals
1661 
1664 class bytes : public object {
1665 public:
1667 
1668  // Allow implicit conversion:
1669  // NOLINTNEXTLINE(google-explicit-constructor)
1670  bytes(const char *c = "") : object(PYBIND11_BYTES_FROM_STRING(c), stolen_t{}) {
1671  if (!m_ptr) {
1672  pybind11_fail("Could not allocate bytes object!");
1673  }
1674  }
1675 
1677  bytes(const char *c, const SzType &n)
1679  if (!m_ptr) {
1680  pybind11_fail("Could not allocate bytes object!");
1681  }
1682  }
1683 
1684  // Allow implicit conversion:
1685  // NOLINTNEXTLINE(google-explicit-constructor)
1686  bytes(const std::string &s) : bytes(s.data(), s.size()) {}
1687 
1688  explicit bytes(const pybind11::str &s);
1689 
1690  // NOLINTNEXTLINE(google-explicit-constructor)
1691  operator std::string() const { return string_op<std::string>(); }
1692 
1693 #ifdef PYBIND11_HAS_STRING_VIEW
1694  // enable_if is needed to avoid "ambiguous conversion" errors (see PR #3521).
1696  // NOLINTNEXTLINE(google-explicit-constructor)
1697  bytes(T s) : bytes(s.data(), s.size()) {}
1698 
1699  // Obtain a string view that views the current `bytes` buffer value. Note that this is only
1700  // valid so long as the `bytes` instance remains alive and so generally should not outlive the
1701  // lifetime of the `bytes` instance.
1702  // NOLINTNEXTLINE(google-explicit-constructor)
1703  operator std::string_view() const { return string_op<std::string_view>(); }
1704 #endif
1705 private:
1706  template <typename T>
1707  T string_op() const {
1708  char *buffer = nullptr;
1709  ssize_t length = 0;
1710  if (PyBytes_AsStringAndSize(m_ptr, &buffer, &length) != 0) {
1711  throw error_already_set();
1712  }
1713  return {buffer, static_cast<size_t>(length)};
1714  }
1715 };
1716 // Note: breathe >= 4.17.0 will fail to build docs if the below two constructors
1717 // are included in the doxygen group; close here and reopen after as a workaround
1719 
1720 inline bytes::bytes(const pybind11::str &s) {
1721  object temp = s;
1722  if (PyUnicode_Check(s.ptr())) {
1723  temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(s.ptr()));
1724  if (!temp) {
1725  throw error_already_set();
1726  }
1727  }
1728  char *buffer = nullptr;
1729  ssize_t length = 0;
1730  if (PyBytes_AsStringAndSize(temp.ptr(), &buffer, &length) != 0) {
1731  throw error_already_set();
1732  }
1733  auto obj = reinterpret_steal<object>(PYBIND11_BYTES_FROM_STRING_AND_SIZE(buffer, length));
1734  if (!obj) {
1735  pybind11_fail("Could not allocate bytes object!");
1736  }
1737  m_ptr = obj.release().ptr();
1738 }
1739 
1740 inline str::str(const bytes &b) {
1741  char *buffer = nullptr;
1742  ssize_t length = 0;
1743  if (PyBytes_AsStringAndSize(b.ptr(), &buffer, &length) != 0) {
1744  throw error_already_set();
1745  }
1746  auto obj = reinterpret_steal<object>(PyUnicode_FromStringAndSize(buffer, length));
1747  if (!obj) {
1748  if (PyErr_Occurred()) {
1749  throw error_already_set();
1750  }
1751  pybind11_fail("Could not allocate string object!");
1752  }
1753  m_ptr = obj.release().ptr();
1754 }
1755 
1758 class bytearray : public object {
1759 public:
1760  PYBIND11_OBJECT_CVT(bytearray, object, PyByteArray_Check, PyByteArray_FromObject)
1761 
1763  bytearray(const char *c, const SzType &n)
1764  : object(PyByteArray_FromStringAndSize(c, ssize_t_cast(n)), stolen_t{}) {
1765  if (!m_ptr) {
1766  pybind11_fail("Could not allocate bytearray object!");
1767  }
1768  }
1769 
1770  bytearray() : bytearray("", 0) {}
1771 
1772  explicit bytearray(const std::string &s) : bytearray(s.data(), s.size()) {}
1773 
1774  size_t size() const { return static_cast<size_t>(PyByteArray_Size(m_ptr)); }
1775 
1776  explicit operator std::string() const {
1777  char *buffer = PyByteArray_AS_STRING(m_ptr);
1778  ssize_t size = PyByteArray_GET_SIZE(m_ptr);
1779  return std::string(buffer, static_cast<size_t>(size));
1780  }
1781 };
1782 // Note: breathe >= 4.17.0 will fail to build docs if the below two constructors
1783 // are included in the doxygen group; close here and reopen after as a workaround
1785 
1788 class none : public object {
1789 public:
1791  none() : object(Py_None, borrowed_t{}) {}
1792 };
1793 
1794 class ellipsis : public object {
1795 public:
1797  ellipsis() : object(Py_Ellipsis, borrowed_t{}) {}
1798 };
1799 
1800 class bool_ : public object {
1801 public:
1802  PYBIND11_OBJECT_CVT(bool_, object, PyBool_Check, raw_bool)
1803  bool_() : object(Py_False, borrowed_t{}) {}
1804  // Allow implicit conversion from and to `bool`:
1805  // NOLINTNEXTLINE(google-explicit-constructor)
1806  bool_(bool value) : object(value ? Py_True : Py_False, borrowed_t{}) {}
1807  // NOLINTNEXTLINE(google-explicit-constructor)
1808  operator bool() const { return (m_ptr != nullptr) && PyLong_AsLong(m_ptr) != 0; }
1809 
1810 private:
1812  static PyObject *raw_bool(PyObject *op) {
1813  const auto value = PyObject_IsTrue(op);
1814  if (value == -1) {
1815  return nullptr;
1816  }
1817  return handle(value != 0 ? Py_True : Py_False).inc_ref().ptr();
1818  }
1819 };
1820 
1822 // Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1;
1823 // otherwise you get back the unsigned long or unsigned long long value cast to (Unsigned).
1824 // (The distinction is critically important when casting a returned -1 error value to some other
1825 // unsigned type: (A)-1 != (B)-1 when A and B are unsigned types of different sizes).
1826 template <typename Unsigned>
1827 Unsigned as_unsigned(PyObject *o) {
1828  if (sizeof(Unsigned) <= sizeof(unsigned long)) {
1829  unsigned long v = PyLong_AsUnsignedLong(o);
1830  return v == (unsigned long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
1831  }
1832  unsigned long long v = PyLong_AsUnsignedLongLong(o);
1833  return v == (unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
1834 }
1836 
1837 class int_ : public object {
1838 public:
1839  PYBIND11_OBJECT_CVT(int_, object, PYBIND11_LONG_CHECK, PyNumber_Long)
1840  int_() : object(PyLong_FromLong(0), stolen_t{}) {}
1841  // Allow implicit conversion from C++ integral types:
1843  // NOLINTNEXTLINE(google-explicit-constructor)
1845  if (sizeof(T) <= sizeof(long)) {
1847  m_ptr = PyLong_FromLong((long) value);
1848  } else {
1849  m_ptr = PyLong_FromUnsignedLong((unsigned long) value);
1850  }
1851  } else {
1853  m_ptr = PyLong_FromLongLong((long long) value);
1854  } else {
1855  m_ptr = PyLong_FromUnsignedLongLong((unsigned long long) value);
1856  }
1857  }
1858  if (!m_ptr) {
1859  pybind11_fail("Could not allocate int object!");
1860  }
1861  }
1862 
1864  // NOLINTNEXTLINE(google-explicit-constructor)
1865  operator T() const {
1866  return std::is_unsigned<T>::value ? detail::as_unsigned<T>(m_ptr)
1867  : sizeof(T) <= sizeof(long) ? (T) PyLong_AsLong(m_ptr)
1868  : (T) PYBIND11_LONG_AS_LONGLONG(m_ptr);
1869  }
1870 };
1871 
1872 class float_ : public object {
1873 public:
1874  PYBIND11_OBJECT_CVT(float_, object, PyFloat_Check, PyNumber_Float)
1875  // Allow implicit conversion from float/double:
1876  // NOLINTNEXTLINE(google-explicit-constructor)
1877  float_(float value) : object(PyFloat_FromDouble((double) value), stolen_t{}) {
1878  if (!m_ptr) {
1879  pybind11_fail("Could not allocate float object!");
1880  }
1881  }
1882  // NOLINTNEXTLINE(google-explicit-constructor)
1883  float_(double value = .0) : object(PyFloat_FromDouble((double) value), stolen_t{}) {
1884  if (!m_ptr) {
1885  pybind11_fail("Could not allocate float object!");
1886  }
1887  }
1888  // NOLINTNEXTLINE(google-explicit-constructor)
1889  operator float() const { return (float) PyFloat_AsDouble(m_ptr); }
1890  // NOLINTNEXTLINE(google-explicit-constructor)
1891  operator double() const { return (double) PyFloat_AsDouble(m_ptr); }
1892 };
1893 
1894 class weakref : public object {
1895 public:
1896  PYBIND11_OBJECT_CVT_DEFAULT(weakref, object, PyWeakref_Check, raw_weakref)
1897  explicit weakref(handle obj, handle callback = {})
1898  : object(PyWeakref_NewRef(obj.ptr(), callback.ptr()), stolen_t{}) {
1899  if (!m_ptr) {
1900  if (PyErr_Occurred()) {
1901  throw error_already_set();
1902  }
1903  pybind11_fail("Could not allocate weak reference!");
1904  }
1905  }
1906 
1907 private:
1908  static PyObject *raw_weakref(PyObject *o) { return PyWeakref_NewRef(o, nullptr); }
1909 };
1910 
1911 class slice : public object {
1912 public:
1913  PYBIND11_OBJECT_DEFAULT(slice, object, PySlice_Check)
1915  : object(PySlice_New(start.ptr(), stop.ptr(), step.ptr()), stolen_t{}) {
1916  if (!m_ptr) {
1917  pybind11_fail("Could not allocate slice object!");
1918  }
1919  }
1920 
1921 #ifdef PYBIND11_HAS_OPTIONAL
1922  slice(std::optional<ssize_t> start, std::optional<ssize_t> stop, std::optional<ssize_t> step)
1923  : slice(index_to_object(start), index_to_object(stop), index_to_object(step)) {}
1924 #else
1925  slice(ssize_t start_, ssize_t stop_, ssize_t step_)
1926  : slice(int_(start_), int_(stop_), int_(step_)) {}
1927 #endif
1928 
1929  bool
1930  compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const {
1931  return PySlice_GetIndicesEx((PYBIND11_SLICE_OBJECT *) m_ptr,
1932  (ssize_t) length,
1933  (ssize_t *) start,
1934  (ssize_t *) stop,
1935  (ssize_t *) step,
1936  (ssize_t *) slicelength)
1937  == 0;
1938  }
1939  bool compute(
1940  ssize_t length, ssize_t *start, ssize_t *stop, ssize_t *step, ssize_t *slicelength) const {
1941  return PySlice_GetIndicesEx(
1942  (PYBIND11_SLICE_OBJECT *) m_ptr, length, start, stop, step, slicelength)
1943  == 0;
1944  }
1945 
1946 private:
1947  template <typename T>
1948  static object index_to_object(T index) {
1949  return index ? object(int_(*index)) : object(none());
1950  }
1951 };
1952 
1953 class capsule : public object {
1954 public:
1955  PYBIND11_OBJECT_DEFAULT(capsule, object, PyCapsule_CheckExact)
1956  PYBIND11_DEPRECATED("Use reinterpret_borrow<capsule>() or reinterpret_steal<capsule>()")
1957  capsule(PyObject *ptr, bool is_borrowed)
1958  : object(is_borrowed ? object(ptr, borrowed_t{}) : object(ptr, stolen_t{})) {}
1959 
1960  explicit capsule(const void *value,
1961  const char *name = nullptr,
1962  PyCapsule_Destructor destructor = nullptr)
1963  : object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) {
1964  if (!m_ptr) {
1965  throw error_already_set();
1966  }
1967  }
1968 
1969  PYBIND11_DEPRECATED("Please use the ctor with value, name, destructor args")
1970  capsule(const void *value, PyCapsule_Destructor destructor)
1971  : object(PyCapsule_New(const_cast<void *>(value), nullptr, destructor), stolen_t{}) {
1972  if (!m_ptr) {
1973  throw error_already_set();
1974  }
1975  }
1976 
1978  capsule(const void *value, void (*destructor)(void *)) {
1979  initialize_with_void_ptr_destructor(value, nullptr, destructor);
1980  }
1981 
1982  capsule(const void *value, const char *name, void (*destructor)(void *)) {
1983  initialize_with_void_ptr_destructor(value, name, destructor);
1984  }
1985 
1986  explicit capsule(void (*destructor)()) {
1987  m_ptr = PyCapsule_New(reinterpret_cast<void *>(destructor), nullptr, [](PyObject *o) {
1988  const char *name = get_name_in_error_scope(o);
1989  auto destructor = reinterpret_cast<void (*)()>(PyCapsule_GetPointer(o, name));
1990  if (destructor == nullptr) {
1991  throw error_already_set();
1992  }
1993  destructor();
1994  });
1995 
1996  if (!m_ptr) {
1997  throw error_already_set();
1998  }
1999  }
2000 
2001  template <typename T>
2002  operator T *() const { // NOLINT(google-explicit-constructor)
2003  return get_pointer<T>();
2004  }
2005 
2007  template <typename T = void>
2008  T *get_pointer() const {
2009  const auto *name = this->name();
2010  T *result = static_cast<T *>(PyCapsule_GetPointer(m_ptr, name));
2011  if (!result) {
2012  throw error_already_set();
2013  }
2014  return result;
2015  }
2016 
2018  void set_pointer(const void *value) {
2019  if (PyCapsule_SetPointer(m_ptr, const_cast<void *>(value)) != 0) {
2020  throw error_already_set();
2021  }
2022  }
2023 
2024  const char *name() const {
2025  const char *name = PyCapsule_GetName(m_ptr);
2026  if ((name == nullptr) && PyErr_Occurred()) {
2027  throw error_already_set();
2028  }
2029  return name;
2030  }
2031 
2033  void set_name(const char *new_name) {
2034  if (PyCapsule_SetName(m_ptr, new_name) != 0) {
2035  throw error_already_set();
2036  }
2037  }
2038 
2039 private:
2040  static const char *get_name_in_error_scope(PyObject *o) {
2041  error_scope error_guard;
2042 
2043  const char *name = PyCapsule_GetName(o);
2044  if ((name == nullptr) && PyErr_Occurred()) {
2045  // write out and consume error raised by call to PyCapsule_GetName
2046  PyErr_WriteUnraisable(o);
2047  }
2048 
2049  return name;
2050  }
2051 
2052  void initialize_with_void_ptr_destructor(const void *value,
2053  const char *name,
2054  void (*destructor)(void *)) {
2055  m_ptr = PyCapsule_New(const_cast<void *>(value), name, [](PyObject *o) {
2056  // guard if destructor called while err indicator is set
2057  error_scope error_guard;
2058  auto destructor = reinterpret_cast<void (*)(void *)>(PyCapsule_GetContext(o));
2059  if (destructor == nullptr && PyErr_Occurred()) {
2060  throw error_already_set();
2061  }
2062  const char *name = get_name_in_error_scope(o);
2063  void *ptr = PyCapsule_GetPointer(o, name);
2064  if (ptr == nullptr) {
2065  throw error_already_set();
2066  }
2067 
2068  if (destructor != nullptr) {
2069  destructor(ptr);
2070  }
2071  });
2072 
2073  if (!m_ptr || PyCapsule_SetContext(m_ptr, reinterpret_cast<void *>(destructor)) != 0) {
2074  throw error_already_set();
2075  }
2076  }
2077 };
2078 
2079 class tuple : public object {
2080 public:
2081  PYBIND11_OBJECT_CVT(tuple, object, PyTuple_Check, PySequence_Tuple)
2082  template <typename SzType = ssize_t,
2084  // Some compilers generate link errors when using `const SzType &` here:
2085  explicit tuple(SzType size = 0) : object(PyTuple_New(ssize_t_cast(size)), stolen_t{}) {
2086  if (!m_ptr) {
2087  pybind11_fail("Could not allocate tuple object!");
2088  }
2089  }
2090  size_t size() const { return (size_t) PyTuple_Size(m_ptr); }
2091  bool empty() const { return size() == 0; }
2092  detail::tuple_accessor operator[](size_t index) const { return {*this, index}; }
2095  return object::operator[](std::forward<T>(o));
2096  }
2097  detail::tuple_iterator begin() const { return {*this, 0}; }
2098  detail::tuple_iterator end() const { return {*this, PyTuple_GET_SIZE(m_ptr)}; }
2099 };
2100 
2101 // We need to put this into a separate function because the Intel compiler
2102 // fails to compile enable_if_t<all_of<is_keyword_or_ds<Args>...>::value> part below
2103 // (tested with ICC 2021.1 Beta 20200827).
2104 template <typename... Args>
2105 constexpr bool args_are_all_keyword_or_ds() {
2106  return detail::all_of<detail::is_keyword_or_ds<Args>...>::value;
2107 }
2108 
2109 class dict : public object {
2110 public:
2111  PYBIND11_OBJECT_CVT(dict, object, PyDict_Check, raw_dict)
2112  dict() : object(PyDict_New(), stolen_t{}) {
2113  if (!m_ptr) {
2114  pybind11_fail("Could not allocate dict object!");
2115  }
2116  }
2117  template <typename... Args,
2118  typename = detail::enable_if_t<args_are_all_keyword_or_ds<Args...>()>,
2119  // MSVC workaround: it can't compile an out-of-line definition, so defer the
2120  // collector
2121  typename collector = detail::deferred_t<detail::unpacking_collector<>, Args...>>
2122  explicit dict(Args &&...args) : dict(collector(std::forward<Args>(args)...).kwargs()) {}
2123 
2124  size_t size() const { return (size_t) PyDict_Size(m_ptr); }
2125  bool empty() const { return size() == 0; }
2126  detail::dict_iterator begin() const { return {*this, 0}; }
2127  detail::dict_iterator end() const { return {}; }
2128  void clear() /* py-non-const */ { PyDict_Clear(ptr()); }
2129  template <typename T>
2130  bool contains(T &&key) const {
2131  auto result = PyDict_Contains(m_ptr, detail::object_or_cast(std::forward<T>(key)).ptr());
2132  if (result == -1) {
2133  throw error_already_set();
2134  }
2135  return result == 1;
2136  }
2137 
2138 private:
2140  static PyObject *raw_dict(PyObject *op) {
2141  if (PyDict_Check(op)) {
2142  return handle(op).inc_ref().ptr();
2143  }
2144  return PyObject_CallFunctionObjArgs((PyObject *) &PyDict_Type, op, nullptr);
2145  }
2146 };
2147 
2148 class sequence : public object {
2149 public:
2150  PYBIND11_OBJECT_DEFAULT(sequence, object, PySequence_Check)
2151  size_t size() const {
2152  ssize_t result = PySequence_Size(m_ptr);
2153  if (result == -1) {
2154  throw error_already_set();
2155  }
2156  return (size_t) result;
2157  }
2158  bool empty() const { return size() == 0; }
2159  detail::sequence_accessor operator[](size_t index) const { return {*this, index}; }
2162  return object::operator[](std::forward<T>(o));
2163  }
2164  detail::sequence_iterator begin() const { return {*this, 0}; }
2165  detail::sequence_iterator end() const { return {*this, PySequence_Size(m_ptr)}; }
2166 };
2167 
2168 class list : public object {
2169 public:
2170  PYBIND11_OBJECT_CVT(list, object, PyList_Check, PySequence_List)
2171  template <typename SzType = ssize_t,
2173  // Some compilers generate link errors when using `const SzType &` here:
2174  explicit list(SzType size = 0) : object(PyList_New(ssize_t_cast(size)), stolen_t{}) {
2175  if (!m_ptr) {
2176  pybind11_fail("Could not allocate list object!");
2177  }
2178  }
2179  size_t size() const { return (size_t) PyList_Size(m_ptr); }
2180  bool empty() const { return size() == 0; }
2181  detail::list_accessor operator[](size_t index) const { return {*this, index}; }
2184  return object::operator[](std::forward<T>(o));
2185  }
2186  detail::list_iterator begin() const { return {*this, 0}; }
2187  detail::list_iterator end() const { return {*this, PyList_GET_SIZE(m_ptr)}; }
2188  template <typename T>
2189  void append(T &&val) /* py-non-const */ {
2190  if (PyList_Append(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) != 0) {
2191  throw error_already_set();
2192  }
2193  }
2194  template <typename IdxType,
2195  typename ValType,
2197  void insert(const IdxType &index, ValType &&val) /* py-non-const */ {
2198  if (PyList_Insert(m_ptr,
2199  ssize_t_cast(index),
2200  detail::object_or_cast(std::forward<ValType>(val)).ptr())
2201  != 0) {
2202  throw error_already_set();
2203  }
2204  }
2205  void clear() /* py-non-const */ {
2206  if (PyList_SetSlice(m_ptr, 0, PyList_Size(m_ptr), nullptr) == -1) {
2207  throw error_already_set();
2208  }
2209  }
2210 };
2211 
2212 class args : public tuple {
2213  PYBIND11_OBJECT_DEFAULT(args, tuple, PyTuple_Check)
2214 };
2215 class kwargs : public dict {
2216  PYBIND11_OBJECT_DEFAULT(kwargs, dict, PyDict_Check)
2217 };
2218 
2219 class anyset : public object {
2220 public:
2221  PYBIND11_OBJECT(anyset, object, PyAnySet_Check)
2222  size_t size() const { return static_cast<size_t>(PySet_Size(m_ptr)); }
2223  bool empty() const { return size() == 0; }
2224  template <typename T>
2225  bool contains(T &&val) const {
2226  auto result = PySet_Contains(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr());
2227  if (result == -1) {
2228  throw error_already_set();
2229  }
2230  return result == 1;
2231  }
2232 };
2233 
2234 class set : public anyset {
2235 public:
2236  PYBIND11_OBJECT_CVT(set, anyset, PySet_Check, PySet_New)
2237  set() : anyset(PySet_New(nullptr), stolen_t{}) {
2238  if (!m_ptr) {
2239  pybind11_fail("Could not allocate set object!");
2240  }
2241  }
2242  template <typename T>
2243  bool add(T &&val) /* py-non-const */ {
2244  return PySet_Add(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 0;
2245  }
2246  void clear() /* py-non-const */ { PySet_Clear(m_ptr); }
2247 };
2248 
2249 class frozenset : public anyset {
2250 public:
2251  PYBIND11_OBJECT_CVT(frozenset, anyset, PyFrozenSet_Check, PyFrozenSet_New)
2252 };
2253 
2254 class function : public object {
2255 public:
2256  PYBIND11_OBJECT_DEFAULT(function, object, PyCallable_Check)
2258  handle fun = detail::get_function(m_ptr);
2259  if (fun && PyCFunction_Check(fun.ptr())) {
2260  return fun;
2261  }
2262  return handle();
2263  }
2264  bool is_cpp_function() const { return (bool) cpp_function(); }
2265 };
2266 
2267 class staticmethod : public object {
2268 public:
2269  PYBIND11_OBJECT_CVT(staticmethod, object, detail::PyStaticMethod_Check, PyStaticMethod_New)
2270 };
2271 
2272 class buffer : public object {
2273 public:
2274  PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
2275 
2276  buffer_info request(bool writable = false) const {
2277  int flags = PyBUF_STRIDES | PyBUF_FORMAT;
2278  if (writable) {
2279  flags |= PyBUF_WRITABLE;
2280  }
2281  auto *view = new Py_buffer();
2282  if (PyObject_GetBuffer(m_ptr, view, flags) != 0) {
2283  delete view;
2284  throw error_already_set();
2285  }
2286  return buffer_info(view);
2287  }
2288 };
2289 
2290 class memoryview : public object {
2291 public:
2292  PYBIND11_OBJECT_CVT(memoryview, object, PyMemoryView_Check, PyMemoryView_FromObject)
2293 
2294 
2303  explicit memoryview(const buffer_info &info) {
2304  if (!info.view()) {
2305  pybind11_fail("Prohibited to create memoryview without Py_buffer");
2306  }
2307  // Note: PyMemoryView_FromBuffer never increments obj reference.
2308  m_ptr = (info.view()->obj) ? PyMemoryView_FromObject(info.view()->obj)
2309  : PyMemoryView_FromBuffer(info.view());
2310  if (!m_ptr) {
2311  pybind11_fail("Unable to create memoryview from buffer descriptor");
2312  }
2313  }
2314 
2339  static memoryview from_buffer(void *ptr,
2340  ssize_t itemsize,
2341  const char *format,
2342  detail::any_container<ssize_t> shape,
2343  detail::any_container<ssize_t> strides,
2344  bool readonly = false);
2345 
2346  static memoryview from_buffer(const void *ptr,
2347  ssize_t itemsize,
2348  const char *format,
2349  detail::any_container<ssize_t> shape,
2350  detail::any_container<ssize_t> strides) {
2351  return memoryview::from_buffer(
2352  const_cast<void *>(ptr), itemsize, format, std::move(shape), std::move(strides), true);
2353  }
2354 
2355  template <typename T>
2356  static memoryview from_buffer(T *ptr,
2357  detail::any_container<ssize_t> shape,
2358  detail::any_container<ssize_t> strides,
2359  bool readonly = false) {
2360  return memoryview::from_buffer(reinterpret_cast<void *>(ptr),
2361  sizeof(T),
2363  std::move(shape),
2364  std::move(strides),
2365  readonly);
2366  }
2367 
2368  template <typename T>
2369  static memoryview from_buffer(const T *ptr,
2370  detail::any_container<ssize_t> shape,
2371  detail::any_container<ssize_t> strides) {
2372  return memoryview::from_buffer(
2373  const_cast<T *>(ptr), std::move(shape), std::move(strides), true);
2374  }
2375 
2388  static memoryview from_memory(void *mem, ssize_t size, bool readonly = false) {
2389  PyObject *ptr = PyMemoryView_FromMemory(
2390  reinterpret_cast<char *>(mem), size, (readonly) ? PyBUF_READ : PyBUF_WRITE);
2391  if (!ptr) {
2392  pybind11_fail("Could not allocate memoryview object!");
2393  }
2394  return memoryview(object(ptr, stolen_t{}));
2395  }
2396 
2397  static memoryview from_memory(const void *mem, ssize_t size) {
2398  return memoryview::from_memory(const_cast<void *>(mem), size, true);
2399  }
2400 
2401 #ifdef PYBIND11_HAS_STRING_VIEW
2402  static memoryview from_memory(std::string_view mem) {
2403  return from_memory(const_cast<char *>(mem.data()), static_cast<ssize_t>(mem.size()), true);
2404  }
2405 #endif
2406 };
2407 
2409 inline memoryview memoryview::from_buffer(void *ptr,
2410  ssize_t itemsize,
2411  const char *format,
2412  detail::any_container<ssize_t> shape,
2413  detail::any_container<ssize_t> strides,
2414  bool readonly) {
2415  size_t ndim = shape->size();
2416  if (ndim != strides->size()) {
2417  pybind11_fail("memoryview: shape length doesn't match strides length");
2418  }
2419  ssize_t size = ndim != 0u ? 1 : 0;
2420  for (size_t i = 0; i < ndim; ++i) {
2421  size *= (*shape)[i];
2422  }
2423  Py_buffer view;
2424  view.buf = ptr;
2425  view.obj = nullptr;
2426  view.len = size * itemsize;
2427  view.readonly = static_cast<int>(readonly);
2428  view.itemsize = itemsize;
2429  view.format = const_cast<char *>(format);
2430  view.ndim = static_cast<int>(ndim);
2431  view.shape = shape->data();
2432  view.strides = strides->data();
2433  view.suboffsets = nullptr;
2434  view.internal = nullptr;
2435  PyObject *obj = PyMemoryView_FromBuffer(&view);
2436  if (!obj) {
2437  throw error_already_set();
2438  }
2439  return memoryview(object(obj, stolen_t{}));
2440 }
2443 
2446 
2448 inline size_t len(handle h) {
2449  ssize_t result = PyObject_Length(h.ptr());
2450  if (result < 0) {
2451  throw error_already_set();
2452  }
2453  return (size_t) result;
2454 }
2455 
2458 inline size_t len_hint(handle h) {
2459  ssize_t result = PyObject_LengthHint(h.ptr(), 0);
2460  if (result < 0) {
2461  // Sometimes a length can't be determined at all (eg generators)
2462  // In which case simply return 0
2463  PyErr_Clear();
2464  return 0;
2465  }
2466  return (size_t) result;
2467 }
2468 
2469 inline str repr(handle h) {
2470  PyObject *str_value = PyObject_Repr(h.ptr());
2471  if (!str_value) {
2472  throw error_already_set();
2473  }
2474  return reinterpret_steal<str>(str_value);
2475 }
2476 
2477 inline iterator iter(handle obj) {
2478  PyObject *result = PyObject_GetIter(obj.ptr());
2479  if (!result) {
2480  throw error_already_set();
2481  }
2482  return reinterpret_steal<iterator>(result);
2483 }
2485 
2487 template <typename D>
2489  return iter(derived());
2490 }
2491 template <typename D>
2493  return iterator::sentinel();
2494 }
2495 template <typename D>
2497  return {derived(), reinterpret_borrow<object>(key)};
2498 }
2499 template <typename D>
2501  return {derived(), std::move(key)};
2502 }
2503 template <typename D>
2505  return {derived(), pybind11::str(key)};
2506 }
2507 template <typename D>
2509  return {derived(), reinterpret_borrow<object>(key)};
2510 }
2511 template <typename D>
2513  return {derived(), std::move(key)};
2514 }
2515 template <typename D>
2517  return {derived(), key};
2518 }
2519 template <typename D>
2521  return args_proxy(derived().ptr());
2522 }
2523 template <typename D>
2524 template <typename T>
2525 bool object_api<D>::contains(T &&item) const {
2526  return attr("__contains__")(std::forward<T>(item)).template cast<bool>();
2527 }
2528 
2529 template <typename D>
2531  return pybind11::str(derived());
2532 }
2533 
2534 template <typename D>
2536  return attr("__doc__");
2537 }
2538 
2539 template <typename D>
2541  return type::handle_of(derived());
2542 }
2543 
2544 template <typename D>
2546  int rv = PyObject_RichCompareBool(derived().ptr(), other.derived().ptr(), value);
2547  if (rv == -1) {
2548  throw error_already_set();
2549  }
2550  return rv == 1;
2551 }
2552 
2553 #define PYBIND11_MATH_OPERATOR_UNARY(op, fn) \
2554  template <typename D> \
2555  object object_api<D>::op() const { \
2556  object result = reinterpret_steal<object>(fn(derived().ptr())); \
2557  if (!result.ptr()) \
2558  throw error_already_set(); \
2559  return result; \
2560  }
2561 
2562 #define PYBIND11_MATH_OPERATOR_BINARY(op, fn) \
2563  template <typename D> \
2564  object object_api<D>::op(object_api const &other) const { \
2565  object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
2566  if (!result.ptr()) \
2567  throw error_already_set(); \
2568  return result; \
2569  }
2570 
2571 #define PYBIND11_MATH_OPERATOR_BINARY_INPLACE(iop, fn) \
2572  template <typename D> \
2573  object object_api<D>::iop(object_api const &other) { \
2574  object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
2575  if (!result.ptr()) \
2576  throw error_already_set(); \
2577  return result; \
2578  }
2579 
2580 PYBIND11_MATH_OPERATOR_UNARY(operator~, PyNumber_Invert)
2581 PYBIND11_MATH_OPERATOR_UNARY(operator-, PyNumber_Negative)
2582 PYBIND11_MATH_OPERATOR_BINARY(operator+, PyNumber_Add)
2583 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator+=, PyNumber_InPlaceAdd)
2584 PYBIND11_MATH_OPERATOR_BINARY(operator-, PyNumber_Subtract)
2585 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator-=, PyNumber_InPlaceSubtract)
2586 PYBIND11_MATH_OPERATOR_BINARY(operator*, PyNumber_Multiply)
2587 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator*=, PyNumber_InPlaceMultiply)
2588 PYBIND11_MATH_OPERATOR_BINARY(operator/, PyNumber_TrueDivide)
2589 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator/=, PyNumber_InPlaceTrueDivide)
2590 PYBIND11_MATH_OPERATOR_BINARY(operator|, PyNumber_Or)
2591 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator|=, PyNumber_InPlaceOr)
2592 PYBIND11_MATH_OPERATOR_BINARY(operator&, PyNumber_And)
2593 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator&=, PyNumber_InPlaceAnd)
2594 PYBIND11_MATH_OPERATOR_BINARY(operator^, PyNumber_Xor)
2595 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator^=, PyNumber_InPlaceXor)
2596 PYBIND11_MATH_OPERATOR_BINARY(operator<<, PyNumber_Lshift)
2597 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator<<=, PyNumber_InPlaceLshift)
2598 PYBIND11_MATH_OPERATOR_BINARY(operator>>, PyNumber_Rshift)
2599 PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator>>=, PyNumber_InPlaceRshift)
2600 
2601 #undef PYBIND11_MATH_OPERATOR_UNARY
2602 #undef PYBIND11_MATH_OPERATOR_BINARY
2603 #undef PYBIND11_MATH_OPERATOR_BINARY_INPLACE
2604 
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:1265
object_api::operator+=
object operator+=(object_api const &other)
PyNone_Check
bool PyNone_Check(PyObject *o)
Definition: pytypes.h:1347
int_
Definition: pytypes.h:1837
str_attr
Definition: pytypes.h:1087
slice::index_to_object
static object index_to_object(T index)
Definition: pytypes.h:1948
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:1535
error_already_set::error_already_set
error_already_set()
Definition: pytypes.h:743
format_descriptor
Definition: wrap/pybind11/include/pybind11/detail/common.h:1055
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:1588
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:1108
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:1770
dict_readonly::increment
void increment()
Definition: pytypes.h:1312
PYBIND11_OBJECT_CVT_DEFAULT
#define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun)
Definition: pytypes.h:1424
object_api::operator>>=
object operator>>=(object_api const &other)
list::end
detail::list_iterator end() const
Definition: pytypes.h:2187
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:1376
isinstance_generic
bool isinstance_generic(handle obj, const std::type_info &tp)
Definition: type_caster_base.h:439
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:2122
object_api::rich_compare
bool rich_compare(object_api const &other, int value) const
Definition: pytypes.h:2545
list::operator[]
detail::item_accessor operator[](T &&o) const
Definition: pytypes.h:2183
error_fetch_and_normalize::error_string
const std::string & error_string() const
Definition: pytypes.h:697
bytes
Definition: pytypes.h:1664
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:2234
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:1300
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
ssize_t
Py_ssize_t ssize_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:508
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:1433
function::is_cpp_function
bool is_cpp_function() const
Definition: pytypes.h:2264
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:241
object_api::operator-=
object operator-=(object_api const &other)
kwargs
Definition: pytypes.h:2215
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:1288
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:2267
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:518
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:1270
list
Definition: pytypes.h:2168
generic_iterator::operator++
It & operator++()
Definition: pytypes.h:1196
bytes::bytes
bytes(const char *c="")
Definition: pytypes.h:1670
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:1634
PYBIND11_OBJECT_CVT
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun)
Definition: pytypes.h:1409
bytes::bytes
bytes(const char *c, const SzType &n)
Definition: pytypes.h:1677
dict_readonly::value_type
std::pair< handle, handle > value_type
Definition: pytypes.h:1303
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:1548
literals
Definition: cast.h:1518
deferred_t
typename deferred_type< T, Us... >::type deferred_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:916
dict_readonly::equal
bool equal(const dict_readonly &b) const
Definition: pytypes.h:1317
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:1356
PYBIND11_WARNING_POP
PYBIND11_WARNING_PUSH PYBIND11_WARNING_POP
Definition: tensor.h:31
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:1953
object_api::str
pybind11::str str() const
Definition: pytypes.h:2530
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:2525
object_api::operator*=
object operator*=(object_api const &other)
object_api::operator&
object operator&(object_api const &other) const
type
Definition: pytypes.h:1527
dict::end
detail::dict_iterator end() const
Definition: pytypes.h:2127
slice::slice
slice(ssize_t start_, ssize_t stop_, ssize_t step_)
Definition: pytypes.h:1925
getattr
object getattr(handle obj, handle name)
Definition: pytypes.h:890
iterator::difference_type
ssize_t difference_type
Definition: pytypes.h:1465
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:1817
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:69
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:2272
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:1279
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:2369
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:2488
iterator
Definition: pytypes.h:1462
memoryview::from_memory
static memoryview from_memory(const void *mem, ssize_t size)
Definition: pytypes.h:2397
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:1296
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:2091
sequence_slow_readwrite::obj
handle obj
Definition: pytypes.h:1295
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:1894
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:1827
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:1269
bool_
Definition: pytypes.h:1800
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:1812
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:1911
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:2179
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:2097
generic_iterator::operator>=
friend bool operator>=(const It &a, const It &b)
Definition: pytypes.h:1238
sequence::empty
bool empty() const
Definition: pytypes.h:2158
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:1289
list_item::set
static void set(handle obj, const IdxType &index, handle val)
Definition: pytypes.h:1145
dict
Definition: pytypes.h:2109
dict_readonly::reference
const value_type reference
Definition: pytypes.h:1304
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:1266
bytearray::bytearray
bytearray(const char *c, const SzType &n)
Definition: pytypes.h:1763
sequence::begin
detail::sequence_iterator begin() const
Definition: pytypes.h:2164
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:2148
sequence_item::key_type
size_t key_type
Definition: pytypes.h:1112
handle::cast
T cast() const
Definition: cast.h:1241
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:2094
type::handle_of
static handle handle_of()
Definition: cast.h:1835
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:1446
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:1464
sequence_fast_readonly::decrement
void decrement()
Definition: pytypes.h:1267
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:1359
return_value_policy::copy
@ copy
args_are_all_keyword_or_ds
constexpr bool args_are_all_keyword_or_ds()
Definition: pytypes.h:2105
args_proxy::operator*
kwargs_proxy operator*() const
Definition: pytypes.h:1369
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:2346
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:2356
dict::clear
void clear()
Definition: pytypes.h:2128
get_function
handle get_function(handle value)
Definition: pytypes.h:945
str::str
str(const char *c="")
Definition: pytypes.h:1578
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:1419
iterator::operator!=
friend bool operator!=(const iterator &a, const iterator &b)
Definition: pytypes.h:1513
anyset::contains
bool contains(T &&val) const
Definition: pytypes.h:2225
list::insert
void insert(const IdxType &index, ValType &&val)
Definition: pytypes.h:2197
object_api::operator>>
object operator>>(object_api const &other) const
object_api::get_type
handle get_type() const
Definition: pytypes.h:2540
slice::compute
bool compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const
Definition: pytypes.h:1930
negation
Definition: wrap/pybind11/include/pybind11/detail/common.h:732
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:1284
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:1758
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:2124
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:2290
sequence::operator[]
detail::item_accessor operator[](T &&o) const
Definition: pytypes.h:2161
is_ds_unpacking
std::is_same< kwargs_proxy, T > is_ds_unpacking
Definition: pytypes.h:1378
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:1844
cpp_function
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
Definition: pybind11.h:107
common.h
args_proxy::args_proxy
args_proxy(handle h)
Definition: pytypes.h:1368
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:1045
str::str
str(const char *c, const SzType &n)
Definition: pytypes.h:1565
simple_collector
Definition: cast.h:1640
kwargs_proxy
Definition: pytypes.h:1361
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:509
bool_::bool_
bool_(bool value)
Definition: pytypes.h:1806
buffer_info.h
set::add
bool add(T &&val)
Definition: pytypes.h:2243
set_error
void set_error(const handle &type, const char *message)
Definition: pytypes.h:346
bytearray::size
size_t size() const
Definition: pytypes.h:1774
tuple::operator[]
detail::tuple_accessor operator[](size_t index) const
Definition: pytypes.h:2092
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:2553
is_keyword
std::is_base_of< arg, T > is_keyword
Python argument categories (using PEP 448 terms)
Definition: pytypes.h:1374
tuple_item::set
static void set(handle obj, const IdxType &index, handle val)
Definition: pytypes.h:1166
str
Definition: pytypes.h:1560
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:1772
dict_readonly::obj
handle obj
Definition: pytypes.h:1320
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:1666
handle::handle
handle(T &obj)
Enable implicit conversion through T::operator PyObject *().
Definition: pytypes.h:247
set::clear
void clear()
Definition: pytypes.h:2246
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:1447
object_api::operator-
object operator-() const
tuple_iterator
generic_iterator< iterator_policies::sequence_fast_readonly > tuple_iterator
Definition: pytypes.h:1327
accessor
Definition: pytypes.h:53
tuple::end
detail::tuple_iterator end() const
Definition: pytypes.h:2098
iterator::operator->
pointer operator->() const
Definition: pytypes.h:1492
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:1302
sequence_slow_readwrite::advance
void advance(ssize_t n)
Definition: pytypes.h:1290
dict::contains
bool contains(T &&key) const
Definition: pytypes.h:2130
handle::ptr
PyObject * ptr() const
Return the underlying PyObject * pointer.
Definition: pytypes.h:250
tuple::size
size_t size() const
Definition: pytypes.h:2090
tuple_item::get
static object get(handle obj, const IdxType &index)
Definition: pytypes.h:1157
iterator::advance
void advance()
Definition: pytypes.h:1516
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:1308
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:1512
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:2159
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:512
dict::empty
bool empty() const
Definition: pytypes.h:2125
obj_attr::get
static object get(handle obj, handle key)
Definition: pytypes.h:1083
iter
iterator iter(handle obj)
Definition: pytypes.h:2477
iterable
Definition: pytypes.h:1553
list::list
list(SzType size=0)
Definition: pytypes.h:2174
object::object
object(handle h, borrowed_t)
Definition: pytypes.h:449
float_::float_
float_(double value=.0)
Definition: pytypes.h:1883
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:1610
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:2126
args
Definition: pytypes.h:2212
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:1366
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:1277
str_attr::key_type
const char * key_type
Definition: pytypes.h:1088
tuple
Definition: pytypes.h:2079
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:2181
memoryview::from_memory
static memoryview from_memory(void *mem, ssize_t size, bool readonly=false)
Definition: pytypes.h:2388
object_api::doc
str_attr_accessor doc() const
Get or set the object's docstring, i.e. obj.__doc__.
Definition: pytypes.h:2535
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
float_
Definition: pytypes.h:1872
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:2189
object_api::operator<=
bool operator<=(object_api const &other) const
Definition: pytypes.h:154
iterator::operator++
iterator operator++(int)
Definition: pytypes.h:1477
list_iterator
generic_iterator< iterator_policies::sequence_fast_readonly > list_iterator
Definition: pytypes.h:1328
PyIterable_Check
bool PyIterable_Check(PyObject *obj)
Definition: pytypes.h:1337
sequence_slow_readwrite::equal
bool equal(const sequence_slow_readwrite &b) const
Definition: pytypes.h:1291
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:1640
accessor_policies
Definition: pytypes.h:54
PYBIND11_MATH_OPERATOR_BINARY
#define PYBIND11_MATH_OPERATOR_BINARY(op, fn)
Definition: pytypes.h:2562
object_api::operator[]
item_accessor operator[](handle key) const
Definition: pytypes.h:2496
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
function
Definition: pytypes.h:2254
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:2571
object_api::attr
obj_attr_accessor attr(handle key) const
Definition: pytypes.h:2508
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:2458
weakref::raw_weakref
static PyObject * raw_weakref(PyObject *o)
Definition: pytypes.h:1908
len
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2448
dict::raw_dict
static PyObject * raw_dict(PyObject *op)
Call the dict Python type – always returns a new reference.
Definition: pytypes.h:2140
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:1335
object::cast
T cast() const &
Definition: cast.h:1300
handle::ptr
PyObject *& ptr()
Definition: pytypes.h:251
bytes::string_op
T string_op() const
Definition: pytypes.h:1707
object_api::operator|
object operator|(object_api const &other) const
none
Definition: pytypes.h:1788
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:2223
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:1334
sequence_fast_readonly::ptr
PyObject ** ptr
Definition: pytypes.h:1273
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:2249
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:1311
reinterpret_steal
T reinterpret_steal(handle h)
Definition: pytypes.h:480
object_api::operator*
args_proxy operator*() const
Definition: pytypes.h:2520
dict_iterator
generic_iterator< iterator_policies::dict_readonly > dict_iterator
Definition: pytypes.h:1335
kwargs_proxy::kwargs_proxy
kwargs_proxy(handle h)
Definition: pytypes.h:1363
list::empty
bool empty() const
Definition: pytypes.h:2180
PyEllipsis_Check
bool PyEllipsis_Check(PyObject *o)
Definition: pytypes.h:1348
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:1939
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:673
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:1292
test_callbacks.value
value
Definition: test_callbacks.py:162
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:1287
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:1484
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:1510
ellipsis
Definition: pytypes.h:1794
sequence_fast_readonly::advance
void advance(ssize_t n)
Definition: pytypes.h:1268
bytes::bytes
bytes(const std::string &s)
Definition: pytypes.h:1686
object_api::end
iterator end() const
Return a sentinel which ends iteration.
Definition: pytypes.h:2492
sequence::end
detail::sequence_iterator end() const
Definition: pytypes.h:2165
list::clear
void clear()
Definition: pytypes.h:2205
pybind11.msg
msg
Definition: wrap/pybind11/pybind11/__init__.py:6
anyset
Definition: pytypes.h:2219
repr
str repr(handle h)
Definition: pytypes.h:2469
list::begin
detail::list_iterator begin() const
Definition: pytypes.h:2186


gtsam
Author(s):
autogenerated on Thu Apr 10 2025 03:03:00