netgen-mesher 6.2.2505.post48.dev0__cp313-cp313-win_amd64.whl → 6.2.2506.post48.dev0__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. netgen/__init__.pyi +3 -3
  2. netgen/cmake/NetgenConfig.cmake +9 -8
  3. netgen/config/__init__.pyi +7 -7
  4. netgen/config/config.py +6 -6
  5. netgen/config/config.pyi +7 -7
  6. netgen/include/core/archive.hpp +18 -3
  7. netgen/include/core/array.hpp +20 -4
  8. netgen/include/core/autodiff.hpp +9 -11
  9. netgen/include/core/autodiffdiff.hpp +0 -2
  10. netgen/include/core/bitarray.hpp +1 -1
  11. netgen/include/core/flags.hpp +1 -1
  12. netgen/include/core/hashtable.hpp +1 -1
  13. netgen/include/core/memtracer.hpp +7 -7
  14. netgen/include/core/ngcore.hpp +5 -0
  15. netgen/include/core/ngcore_api.hpp +11 -0
  16. netgen/include/core/register_archive.hpp +8 -0
  17. netgen/include/core/simd_arm64.hpp +100 -5
  18. netgen/include/core/simd_generic.hpp +187 -6
  19. netgen/include/core/simd_math.hpp +3 -2
  20. netgen/include/core/statushandler.hpp +37 -0
  21. netgen/include/core/table.hpp +2 -2
  22. netgen/include/core/taskmanager.hpp +34 -1
  23. netgen/include/include/netgen_version.hpp +3 -3
  24. netgen/include/meshing/basegeom.hpp +1 -4
  25. netgen/include/meshing/global.hpp +0 -17
  26. netgen/include/meshing/hpref_tet.hpp +41 -0
  27. netgen/include/meshing/hprefinement.hpp +2 -0
  28. netgen/include/meshing/meshtype.hpp +1 -0
  29. netgen/include/meshing/msghandler.hpp +9 -6
  30. netgen/include/meshing/topology.hpp +2 -2
  31. netgen/include/nginterface.h +3 -2
  32. netgen/include/occ/occ_utils.hpp +26 -0
  33. netgen/include/occ/occgeom.hpp +8 -0
  34. netgen/include/pybind11/attr.h +40 -8
  35. netgen/include/pybind11/buffer_info.h +14 -14
  36. netgen/include/pybind11/cast.h +553 -29
  37. netgen/include/pybind11/chrono.h +4 -1
  38. netgen/include/pybind11/conduit/README.txt +15 -0
  39. netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
  40. netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
  41. netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
  42. netgen/include/pybind11/critical_section.h +56 -0
  43. netgen/include/pybind11/detail/class.h +172 -97
  44. netgen/include/pybind11/detail/common.h +270 -189
  45. netgen/include/pybind11/detail/cpp_conduit.h +75 -0
  46. netgen/include/pybind11/detail/descr.h +55 -0
  47. netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
  48. netgen/include/pybind11/detail/exception_translation.h +71 -0
  49. netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
  50. netgen/include/pybind11/detail/init.h +113 -9
  51. netgen/include/pybind11/detail/internals.h +479 -344
  52. netgen/include/pybind11/detail/native_enum_data.h +209 -0
  53. netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
  54. netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
  55. netgen/include/pybind11/detail/type_caster_base.h +506 -133
  56. netgen/include/pybind11/detail/using_smart_holder.h +22 -0
  57. netgen/include/pybind11/detail/value_and_holder.h +90 -0
  58. netgen/include/pybind11/eigen/matrix.h +19 -10
  59. netgen/include/pybind11/eigen/tensor.h +15 -11
  60. netgen/include/pybind11/embed.h +50 -46
  61. netgen/include/pybind11/eval.h +11 -6
  62. netgen/include/pybind11/functional.h +58 -49
  63. netgen/include/pybind11/gil.h +34 -82
  64. netgen/include/pybind11/gil_safe_call_once.h +12 -1
  65. netgen/include/pybind11/gil_simple.h +37 -0
  66. netgen/include/pybind11/native_enum.h +67 -0
  67. netgen/include/pybind11/numpy.h +272 -93
  68. netgen/include/pybind11/pybind11.h +947 -265
  69. netgen/include/pybind11/pytypes.h +127 -21
  70. netgen/include/pybind11/stl/filesystem.h +23 -25
  71. netgen/include/pybind11/stl.h +277 -59
  72. netgen/include/pybind11/stl_bind.h +42 -7
  73. netgen/include/pybind11/subinterpreter.h +299 -0
  74. netgen/include/pybind11/trampoline_self_life_support.h +65 -0
  75. netgen/include/pybind11/typing.h +177 -4
  76. netgen/include/pybind11/warnings.h +75 -0
  77. netgen/lib/libnggui.lib +0 -0
  78. netgen/lib/ngcore.lib +0 -0
  79. netgen/lib/nglib.lib +0 -0
  80. netgen/libnggui.dll +0 -0
  81. netgen/libngguipy.pyd +0 -0
  82. netgen/libngpy/_NgOCC.pyi +220 -141
  83. netgen/libngpy/_csg.pyi +26 -26
  84. netgen/libngpy/_geom2d.pyi +34 -25
  85. netgen/libngpy/_meshing.pyi +262 -111
  86. netgen/libngpy/_stl.pyi +3 -4
  87. netgen/libngpy.pyd +0 -0
  88. netgen/ngcore.dll +0 -0
  89. netgen/nglib.dll +0 -0
  90. netgen/read_gmsh.py +41 -0
  91. netgen/togl.dll +0 -0
  92. netgen/version.py +1 -1
  93. netgen/webgui.py +38 -2
  94. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/METADATA +2 -1
  95. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/RECORD +144 -124
  96. pyngcore/pyngcore.cp313-win_amd64.pyd +0 -0
  97. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boundarycondition.geo +0 -0
  98. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boxcyl.geo +0 -0
  99. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/circle_on_cube.geo +0 -0
  100. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cone.geo +0 -0
  101. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cube.geo +0 -0
  102. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandring.geo +0 -0
  103. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandspheres.geo +0 -0
  104. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemcyl.geo +0 -0
  105. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemsphere.geo +0 -0
  106. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylinder.geo +0 -0
  107. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylsphere.geo +0 -0
  108. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/doc/ng4.pdf +0 -0
  109. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipsoid.geo +0 -0
  110. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipticcyl.geo +0 -0
  111. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/extrusion.geo +0 -0
  112. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/fichera.geo +0 -0
  113. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/frame.step +0 -0
  114. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/hinge.stl +0 -0
  115. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/lshape3d.geo +0 -0
  116. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes.geo +0 -0
  117. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes2.geo +0 -0
  118. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/matrix.geo +0 -0
  119. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ortho.geo +0 -0
  120. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/part1.stl +0 -0
  121. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/period.geo +0 -0
  122. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/exportNeutral.py +0 -0
  123. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/mesh.py +0 -0
  124. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/shaft.geo +0 -0
  125. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/revolution.geo +0 -0
  126. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/screw.step +0 -0
  127. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sculpture.geo +0 -0
  128. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shaft.geo +0 -0
  129. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shell.geo +0 -0
  130. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphere.geo +0 -0
  131. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphereincube.geo +0 -0
  132. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/square.in2d +0 -0
  133. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarecircle.in2d +0 -0
  134. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarehole.in2d +0 -0
  135. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/torus.geo +0 -0
  136. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/trafo.geo +0 -0
  137. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twobricks.geo +0 -0
  138. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocubes.geo +0 -0
  139. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocyl.geo +0 -0
  140. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/AUTHORS +0 -0
  141. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/LICENSE +0 -0
  142. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/WHEEL +0 -0
  143. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/entry_points.txt +0 -0
  144. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/top_level.txt +0 -0
@@ -48,6 +48,9 @@ PYBIND11_NAMESPACE_BEGIN(detail)
48
48
  class args_proxy;
49
49
  bool isinstance_generic(handle obj, const std::type_info &tp);
50
50
 
51
+ template <typename T>
52
+ bool isinstance_native_enum(handle obj, const std::type_info &tp);
53
+
51
54
  // Accessor forward declarations
52
55
  template <typename Policy>
53
56
  class accessor;
@@ -78,7 +81,9 @@ using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T>>;
78
81
  \endrst */
79
82
  template <typename Derived>
80
83
  class object_api : public pyobject_tag {
84
+ object_api() = default;
81
85
  const Derived &derived() const { return static_cast<const Derived &>(*this); }
86
+ friend Derived;
82
87
 
83
88
  public:
84
89
  /** \rst
@@ -113,6 +118,17 @@ public:
113
118
  /// See above (the only difference is that the key is provided as a string literal)
114
119
  str_attr_accessor attr(const char *key) const;
115
120
 
121
+ /** \rst
122
+ Similar to the above attr functions with the difference that the templated Type
123
+ is used to set the `__annotations__` dict value to the corresponding key. Worth noting
124
+ that attr_with_type_hint is implemented in cast.h.
125
+ \endrst */
126
+ template <typename T>
127
+ obj_attr_accessor attr_with_type_hint(handle key) const;
128
+ /// See above (the only difference is that the key is provided as a string literal)
129
+ template <typename T>
130
+ str_attr_accessor attr_with_type_hint(const char *key) const;
131
+
116
132
  /** \rst
117
133
  Matches * unpacking in Python, e.g. to unpack arguments out of a ``tuple``
118
134
  or ``list`` for a function call. Applying another * to the result yields
@@ -182,11 +198,21 @@ public:
182
198
  /// Get or set the object's docstring, i.e. ``obj.__doc__``.
183
199
  str_attr_accessor doc() const;
184
200
 
201
+ /// Get or set the object's annotations, i.e. ``obj.__annotations__``.
202
+ object annotations() const;
203
+
185
204
  /// Return the object's current reference count
186
- int ref_count() const { return static_cast<int>(Py_REFCNT(derived().ptr())); }
205
+ ssize_t ref_count() const {
206
+ #ifdef PYPY_VERSION
207
+ // PyPy uses the top few bits for REFCNT_FROM_PYPY & REFCNT_FROM_PYPY_LIGHT
208
+ // Following pybind11 2.12.1 and older behavior and removing this part
209
+ return static_cast<ssize_t>(static_cast<int>(Py_REFCNT(derived().ptr())));
210
+ #else
211
+ return Py_REFCNT(derived().ptr());
212
+ #endif
213
+ }
187
214
 
188
- // TODO PYBIND11_DEPRECATED(
189
- // "Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
215
+ PYBIND11_DEPRECATED("Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
190
216
  handle get_type() const;
191
217
 
192
218
  private:
@@ -252,7 +278,7 @@ public:
252
278
  inc_ref_counter(1);
253
279
  #endif
254
280
  #ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
255
- if (m_ptr != nullptr && !PyGILState_Check()) {
281
+ if (m_ptr != nullptr && PyGILState_Check() == 0) {
256
282
  throw_gilstate_error("pybind11::handle::inc_ref()");
257
283
  }
258
284
  #endif
@@ -267,7 +293,7 @@ public:
267
293
  \endrst */
268
294
  const handle &dec_ref() const & {
269
295
  #ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
270
- if (m_ptr != nullptr && !PyGILState_Check()) {
296
+ if (m_ptr != nullptr && PyGILState_Check() == 0) {
271
297
  throw_gilstate_error("pybind11::handle::dec_ref()");
272
298
  }
273
299
  #endif
@@ -539,12 +565,6 @@ struct error_fetch_and_normalize {
539
565
  + " failed to obtain the name "
540
566
  "of the normalized active exception type.");
541
567
  }
542
- # if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x07030a00
543
- // This behavior runs the risk of masking errors in the error handling, but avoids a
544
- // conflict with PyPy, which relies on the normalization here to change OSError to
545
- // FileNotFoundError (https://github.com/pybind/pybind11/issues/4075).
546
- m_lazy_error_string = exc_type_name_norm;
547
- # else
548
568
  if (exc_type_name_norm != m_lazy_error_string) {
549
569
  std::string msg = std::string(called)
550
570
  + ": MISMATCH of original and normalized "
@@ -556,7 +576,6 @@ struct error_fetch_and_normalize {
556
576
  msg += ": " + format_value_and_trace();
557
577
  pybind11_fail(msg);
558
578
  }
559
- # endif
560
579
  #endif
561
580
  }
562
581
 
@@ -635,7 +654,7 @@ struct error_fetch_and_normalize {
635
654
 
636
655
  bool have_trace = false;
637
656
  if (m_trace) {
638
- #if !defined(PYPY_VERSION)
657
+ #if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
639
658
  auto *tb = reinterpret_cast<PyTracebackObject *>(m_trace.ptr());
640
659
 
641
660
  // Get the deepest trace possible.
@@ -837,7 +856,8 @@ bool isinstance(handle obj) {
837
856
 
838
857
  template <typename T, detail::enable_if_t<!std::is_base_of<object, T>::value, int> = 0>
839
858
  bool isinstance(handle obj) {
840
- return detail::isinstance_generic(obj, typeid(T));
859
+ return detail::isinstance_native_enum<T>(obj, typeid(T))
860
+ || detail::isinstance_generic(obj, typeid(T));
841
861
  }
842
862
 
843
863
  template <>
@@ -972,6 +992,23 @@ inline PyObject *dict_getitem(PyObject *v, PyObject *key) {
972
992
  return rv;
973
993
  }
974
994
 
995
+ inline PyObject *dict_getitemstringref(PyObject *v, const char *key) {
996
+ #if PY_VERSION_HEX >= 0x030D0000
997
+ PyObject *rv;
998
+ if (PyDict_GetItemStringRef(v, key, &rv) < 0) {
999
+ throw error_already_set();
1000
+ }
1001
+ return rv;
1002
+ #else
1003
+ PyObject *rv = dict_getitemstring(v, key);
1004
+ if (rv == nullptr && PyErr_Occurred()) {
1005
+ throw error_already_set();
1006
+ }
1007
+ Py_XINCREF(rv);
1008
+ return rv;
1009
+ #endif
1010
+ }
1011
+
975
1012
  // Helper aliases/functions to support implicit casting of values given to python
976
1013
  // accessors/methods. When given a pyobject, this simply returns the pyobject as-is; for other C++
977
1014
  // type, the value goes through pybind11::cast(obj) to convert it to an `object`.
@@ -1234,6 +1271,7 @@ protected:
1234
1271
  using pointer = arrow_proxy<const handle>;
1235
1272
 
1236
1273
  sequence_fast_readonly(handle obj, ssize_t n) : ptr(PySequence_Fast_ITEMS(obj.ptr()) + n) {}
1274
+ sequence_fast_readonly() = default;
1237
1275
 
1238
1276
  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1239
1277
  reference dereference() const { return *ptr; }
@@ -1256,6 +1294,7 @@ protected:
1256
1294
  using pointer = arrow_proxy<const sequence_accessor>;
1257
1295
 
1258
1296
  sequence_slow_readwrite(handle obj, ssize_t index) : obj(obj), index(index) {}
1297
+ sequence_slow_readwrite() = default;
1259
1298
 
1260
1299
  reference dereference() const { return {obj, static_cast<size_t>(index)}; }
1261
1300
  void increment() { ++index; }
@@ -1329,7 +1368,7 @@ inline bool PyUnicode_Check_Permissive(PyObject *o) {
1329
1368
  # define PYBIND11_STR_CHECK_FUN PyUnicode_Check
1330
1369
  #endif
1331
1370
 
1332
- inline bool PyStaticMethod_Check(PyObject *o) { return o->ob_type == &PyStaticMethod_Type; }
1371
+ inline bool PyStaticMethod_Check(PyObject *o) { return Py_TYPE(o) == &PyStaticMethod_Type; }
1333
1372
 
1334
1373
  class kwargs_proxy : public handle {
1335
1374
  public:
@@ -1360,6 +1399,18 @@ class simple_collector;
1360
1399
  template <return_value_policy policy = return_value_policy::automatic_reference>
1361
1400
  class unpacking_collector;
1362
1401
 
1402
+ inline object get_scope_module(handle scope) {
1403
+ if (scope) {
1404
+ if (hasattr(scope, "__module__")) {
1405
+ return scope.attr("__module__");
1406
+ }
1407
+ if (hasattr(scope, "__name__")) {
1408
+ return scope.attr("__name__");
1409
+ }
1410
+ }
1411
+ return object();
1412
+ }
1413
+
1363
1414
  PYBIND11_NAMESPACE_END(detail)
1364
1415
 
1365
1416
  // TODO: After the deprecated constructors are removed, this macro can be simplified by
@@ -1443,11 +1494,17 @@ public:
1443
1494
  PYBIND11_OBJECT_DEFAULT(iterator, object, PyIter_Check)
1444
1495
 
1445
1496
  iterator &operator++() {
1497
+ init();
1446
1498
  advance();
1447
1499
  return *this;
1448
1500
  }
1449
1501
 
1450
1502
  iterator operator++(int) {
1503
+ // Note: We must call init() first so that rv.value is
1504
+ // the same as this->value just before calling advance().
1505
+ // Otherwise, dereferencing the returned iterator may call
1506
+ // advance() again and return the 3rd item instead of the 1st.
1507
+ init();
1451
1508
  auto rv = *this;
1452
1509
  advance();
1453
1510
  return rv;
@@ -1455,15 +1512,12 @@ public:
1455
1512
 
1456
1513
  // NOLINTNEXTLINE(readability-const-return-type) // PR #3263
1457
1514
  reference operator*() const {
1458
- if (m_ptr && !value.ptr()) {
1459
- auto &self = const_cast<iterator &>(*this);
1460
- self.advance();
1461
- }
1515
+ init();
1462
1516
  return value;
1463
1517
  }
1464
1518
 
1465
1519
  pointer operator->() const {
1466
- operator*();
1520
+ init();
1467
1521
  return &value;
1468
1522
  }
1469
1523
 
@@ -1486,6 +1540,13 @@ public:
1486
1540
  friend bool operator!=(const iterator &a, const iterator &b) { return a->ptr() != b->ptr(); }
1487
1541
 
1488
1542
  private:
1543
+ void init() const {
1544
+ if (m_ptr && !value.ptr()) {
1545
+ auto &self = const_cast<iterator &>(*this);
1546
+ self.advance();
1547
+ }
1548
+ }
1549
+
1489
1550
  void advance() {
1490
1551
  value = reinterpret_steal<object>(PyIter_Next(m_ptr));
1491
1552
  if (value.ptr() == nullptr && PyErr_Occurred()) {
@@ -1883,13 +1944,14 @@ private:
1883
1944
 
1884
1945
  class slice : public object {
1885
1946
  public:
1886
- PYBIND11_OBJECT_DEFAULT(slice, object, PySlice_Check)
1947
+ PYBIND11_OBJECT(slice, object, PySlice_Check)
1887
1948
  slice(handle start, handle stop, handle step)
1888
1949
  : object(PySlice_New(start.ptr(), stop.ptr(), step.ptr()), stolen_t{}) {
1889
1950
  if (!m_ptr) {
1890
1951
  pybind11_fail("Could not allocate slice object!");
1891
1952
  }
1892
1953
  }
1954
+ slice() : slice(none(), none(), none()) {}
1893
1955
 
1894
1956
  #ifdef PYBIND11_HAS_OPTIONAL
1895
1957
  slice(std::optional<ssize_t> start, std::optional<ssize_t> stop, std::optional<ssize_t> step)
@@ -2175,6 +2237,11 @@ public:
2175
2237
  throw error_already_set();
2176
2238
  }
2177
2239
  }
2240
+ void clear() /* py-non-const */ {
2241
+ if (PyList_SetSlice(m_ptr, 0, PyList_Size(m_ptr), nullptr) == -1) {
2242
+ throw error_already_set();
2243
+ }
2244
+ }
2178
2245
  };
2179
2246
 
2180
2247
  class args : public tuple {
@@ -2184,6 +2251,18 @@ class kwargs : public dict {
2184
2251
  PYBIND11_OBJECT_DEFAULT(kwargs, dict, PyDict_Check)
2185
2252
  };
2186
2253
 
2254
+ // Subclasses of args and kwargs to support type hinting
2255
+ // as defined in PEP 484. See #5357 for more info.
2256
+ template <typename T>
2257
+ class Args : public args {
2258
+ using args::args;
2259
+ };
2260
+
2261
+ template <typename T>
2262
+ class KWArgs : public kwargs {
2263
+ using kwargs::kwargs;
2264
+ };
2265
+
2187
2266
  class anyset : public object {
2188
2267
  public:
2189
2268
  PYBIND11_OBJECT(anyset, object, PyAnySet_Check)
@@ -2504,6 +2583,20 @@ str_attr_accessor object_api<D>::doc() const {
2504
2583
  return attr("__doc__");
2505
2584
  }
2506
2585
 
2586
+ template <typename D>
2587
+ object object_api<D>::annotations() const {
2588
+ // This is needed again because of the lazy annotations added in 3.14+
2589
+ #if PY_VERSION_HEX < 0x030A0000 || PY_VERSION_HEX >= 0x030E0000
2590
+ // https://docs.python.org/3/howto/annotations.html#accessing-the-annotations-dict-of-an-object-in-python-3-9-and-older
2591
+ if (!hasattr(derived(), "__annotations__")) {
2592
+ setattr(derived(), "__annotations__", dict());
2593
+ }
2594
+ return attr("__annotations__");
2595
+ #else
2596
+ return getattr(derived(), "__annotations__", dict());
2597
+ #endif
2598
+ }
2599
+
2507
2600
  template <typename D>
2508
2601
  handle object_api<D>::get_type() const {
2509
2602
  return type::handle_of(derived());
@@ -2570,5 +2663,18 @@ PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator>>=, PyNumber_InPlaceRshift)
2570
2663
  #undef PYBIND11_MATH_OPERATOR_BINARY
2571
2664
  #undef PYBIND11_MATH_OPERATOR_BINARY_INPLACE
2572
2665
 
2666
+ // Meant to return a Python str, but this is not checked.
2667
+ inline object get_module_name_if_available(handle scope) {
2668
+ if (scope) {
2669
+ if (hasattr(scope, "__module__")) {
2670
+ return scope.attr("__module__");
2671
+ }
2672
+ if (hasattr(scope, "__name__")) {
2673
+ return scope.attr("__name__");
2674
+ }
2675
+ }
2676
+ return object();
2677
+ }
2678
+
2573
2679
  PYBIND11_NAMESPACE_END(detail)
2574
2680
  PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
@@ -4,36 +4,32 @@
4
4
 
5
5
  #pragma once
6
6
 
7
- #include "../pybind11.h"
8
- #include "../detail/common.h"
9
- #include "../detail/descr.h"
10
- #include "../cast.h"
11
- #include "../pytypes.h"
7
+ #include <pybind11/cast.h>
8
+ #include <pybind11/detail/common.h>
9
+ #include <pybind11/detail/descr.h>
10
+ #include <pybind11/pybind11.h>
11
+ #include <pybind11/pytypes.h>
12
12
 
13
13
  #include <string>
14
14
 
15
- #ifdef __has_include
16
- # if defined(PYBIND11_CPP17)
17
- # if __has_include(<filesystem>) && \
18
- PY_VERSION_HEX >= 0x03060000
19
- # include <filesystem>
20
- # define PYBIND11_HAS_FILESYSTEM 1
21
- # elif __has_include(<experimental/filesystem>)
22
- # include <experimental/filesystem>
23
- # define PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM 1
24
- # endif
25
- # endif
26
- #endif
27
-
28
- #if !defined(PYBIND11_HAS_FILESYSTEM) && !defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) \
29
- && !defined(PYBIND11_HAS_FILESYSTEM_IS_OPTIONAL)
30
- # error \
31
- "Neither #include <filesystem> nor #include <experimental/filesystem is available. (Use -DPYBIND11_HAS_FILESYSTEM_IS_OPTIONAL to ignore.)"
15
+ #if defined(PYBIND11_HAS_FILESYSTEM)
16
+ # include <filesystem>
17
+ #elif defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
18
+ # include <experimental/filesystem>
19
+ #else
20
+ # error "Neither #include <filesystem> nor #include <experimental/filesystem is available."
32
21
  #endif
33
22
 
34
23
  PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
35
24
  PYBIND11_NAMESPACE_BEGIN(detail)
36
25
 
26
+ #ifdef PYPY_VERSION
27
+ # define PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(...) (__VA_ARGS__)
28
+ #else
29
+ # define PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(...) \
30
+ (reinterpret_cast<void *>(__VA_ARGS__))
31
+ #endif
32
+
37
33
  #if defined(PYBIND11_HAS_FILESYSTEM) || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
38
34
  template <typename T>
39
35
  struct path_caster {
@@ -73,7 +69,8 @@ public:
73
69
  }
74
70
  PyObject *native = nullptr;
75
71
  if constexpr (std::is_same_v<typename T::value_type, char>) {
76
- if (PyUnicode_FSConverter(buf, &native) != 0) {
72
+ if (PyUnicode_FSConverter(buf, PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(&native))
73
+ != 0) {
77
74
  if (auto *c_str = PyBytes_AsString(native)) {
78
75
  // AsString returns a pointer to the internal buffer, which
79
76
  // must not be free'd.
@@ -81,7 +78,8 @@ public:
81
78
  }
82
79
  }
83
80
  } else if constexpr (std::is_same_v<typename T::value_type, wchar_t>) {
84
- if (PyUnicode_FSDecoder(buf, &native) != 0) {
81
+ if (PyUnicode_FSDecoder(buf, PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(&native))
82
+ != 0) {
85
83
  if (auto *c_str = PyUnicode_AsWideCharString(native, nullptr)) {
86
84
  // AsWideCharString returns a new string that must be free'd.
87
85
  value = c_str; // Copies the string.
@@ -98,7 +96,7 @@ public:
98
96
  return true;
99
97
  }
100
98
 
101
- PYBIND11_TYPE_CASTER(T, const_name("os.PathLike"));
99
+ PYBIND11_TYPE_CASTER(T, io_name("os.PathLike | str | bytes", "pathlib.Path"));
102
100
  };
103
101
 
104
102
  #endif // PYBIND11_HAS_FILESYSTEM || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)