* feat!: drop support for Python 3.8 The minimum supported version is now Python 3.9. pybind11 v3.0 was the last release that supports Python 3.8. The deprecation note said that support goes away in 3.1. Remove the code paths that this makes dead: - the `_PyObject_Vectorcall` fallback in `cast.h` - the `frame->f_code` and `frame->f_back` fallbacks in `pytypes.h` - the `PyFrame_FastToLocals` path in `get_type_override` - the conditional `Py_VISIT(Py_TYPE(self))` in `tp_traverse` - `PYBIND11_PYCONFIG_SUPPORT_PY_VERSION_HEX`, the pre-PyConfig interpreter init, and the `widen_chars` helpers in `embed.h` Assisted-by: ClaudeCode:claude-opus-5 * ci(appveyor): use Python 3.9 The AppVeyor job set `PYTHON: 38`, which makes the path `C:\Python38`. The image gives Python 3.9.13 as `C:\Python39`. Assisted-by: ClaudeCode:claude-opus-5 * feat!: require MSVC 2019 or newer Python 3.9 is the new minimum, so MSVC 2017 is no longer needed. Raise the compile-time floor to _MSC_VER 1920 and remove the workarounds that only applied below it: std::launder, fold expressions, weak_from_this, aligned new/delete, the C4100 warning helper, and the func_handle syntax error. AppVeyor now builds with Visual Studio 2019. Assisted-by: ClaudeCode:claude-opus-5 * fix(appveyor): build against the Python that has the test packages CMake 4 has no FindPythonLibs, so pybind11 uses FindPython. FindPython reads the registry before PATH and selected `C:\Python314-x64`, but the test packages go into the Python on PATH. Pass `Python_ROOT_DIR` to name the correct one. Also set `CMAKE_ARCH`. It was never set, so the architecture came from the generator. Visual Studio 2017 defaults to Win32, but Visual Studio 2019 defaults to x64, which made this x86 job build 64-bit code. Assisted-by: ClaudeCode:claude-opus-5 * fix(appveyor): give the linker Python's libs directory The build compiled but failed to link with LNK1104 on a bare `python39.lib`. That name comes from the `#pragma comment(lib, ...)` in pyconfig.h, so the linker needs the directory. CMake 4 has no FindPythonLibs, and FindPython does not add it for this Debug x86 build. Put it on LIB instead. The directory listing is temporary, to confirm the library is present. Assisted-by: ClaudeCode:claude-opus-5 * fix(appveyor): link the release Python library in Debug The image ships python39_d.lib next to python39.lib, so FindPython picks the debug import library for a Debug build. pybind11 undefines _DEBUG around Python.h, so pyconfig.h asks for python39.lib instead and the link failed with LNK1104. Name the release library for the debug slot. Setting LIB does not work, because MSBuild replaces it from the toolset, and it would link both import libraries. Assisted-by: ClaudeCode:claude-opus-5 * chore(appveyor): print link settings to debug LNK1104 Revert the two attempted fixes. Neither changed the failure: setting LIB does not survive MSBuild, and naming the release library for Python_LIBRARY_DEBUG had no effect. Print the Python cache entries and the link settings of a generated project file instead, to see what the linker really gets. Temporary. Assisted-by: ClaudeCode:claude-opus-5 * fix(appveyor): take the release Python library in Debug The generated project file linked C:\Python39\libs\python39_d.lib in the Debug configuration, because the image ships debug binaries next to the release ones. pybind11 undefines _DEBUG around Python.h, so pyconfig.h asks for python39.lib in a #pragma comment(lib), which nothing on the link line satisfies and no library directory holds. Map Debug to the release artifacts. Assisted-by: ClaudeCode:claude-opus-5 * chore(appveyor): drop the temporary link diagnostic Assisted-by: ClaudeCode:claude-opus-5 * fix(tests): guard the unraisable warning filter for pytest < 6 The distro pytest in the Clang and GCC Docker jobs has no PytestUnraisableExceptionWarning, so an unconditional filterwarnings mark makes pytest fail with an INTERNALERROR after the tests pass. Assisted-by: ClaudeCode:claude-opus-5 Claude-Session: https://claude.ai/code/session_01Aimf6HuSz1vLRwBnbxmCTc * docs: address review items on version hints, embed docs, and a PyPy xfail Extend Python_ADDITIONAL_VERSIONS through 3.15, describe the PyConfig behavior of initialize_interpreter, and drop the stale Python 3.8 wording from the PyPy xfail reason. Assisted-by: ClaudeCode:claude-opus-5 * Update README.rst Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com> --------- Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com>
178 lines
4.3 KiB
ReStructuredText
178 lines
4.3 KiB
ReStructuredText
.. _deprecated:
|
|
|
|
Deprecated
|
|
##########
|
|
|
|
Support for C++11 is deprecated and will be removed in a future version. Please
|
|
use at least C++14.
|
|
|
|
Support for FindPythonLibs (not available in CMake 3.26+ mode) is deprecated
|
|
and will be removed in a future version. The default mode is also going to
|
|
change to ``"new"`` from ``"compat"`` in the future.
|
|
|
|
The following features were deprecated before pybind11 3.0, and may be removed
|
|
in minor releases of pybind11 3.x.
|
|
|
|
.. list-table:: Deprecated Features
|
|
:header-rows: 1
|
|
:widths: 30 15 10
|
|
|
|
* - Feature
|
|
- Deprecated Version
|
|
- Year
|
|
* - ``py::metaclass()``
|
|
- 2.1
|
|
- 2017
|
|
* - ``PYBIND11_PLUGIN``
|
|
- 2.2
|
|
- 2017
|
|
* - ``py::set_error()`` replacing ``operator()``
|
|
- 2.12
|
|
- 2024
|
|
* - ``get_type_overload``
|
|
- 2.6
|
|
- 2020
|
|
* - ``call()``
|
|
- 2.0
|
|
- 2016
|
|
* - ``.str()``
|
|
- ?
|
|
-
|
|
* - ``.get_type()``
|
|
- 2.6
|
|
-
|
|
* - ``==`` and ``!=``
|
|
- 2.2
|
|
- 2017
|
|
* - ``.check()``
|
|
- ?
|
|
-
|
|
* - ``object(handle, bool)``
|
|
- ?
|
|
-
|
|
* - ``error_already_set.clear()``
|
|
- 2.2
|
|
- 2017
|
|
* - ``obj.attr(…)`` as ``bool``
|
|
- ?
|
|
-
|
|
* - ``.contains``
|
|
- ? (maybe 2.4)
|
|
-
|
|
* - ``py::capsule`` two-argument with destructor
|
|
- ?
|
|
-
|
|
|
|
|
|
|
|
.. _deprecated_enum:
|
|
|
|
``py::enum_``
|
|
=============
|
|
|
|
This is the original documentation for ``py::enum_``, which is deprecated
|
|
because it is not `PEP 435 compatible <https://peps.python.org/pep-0435/>`_
|
|
(see also `#2332 <https://github.com/pybind/pybind11/issues/2332>`_).
|
|
Please prefer ``py::native_enum`` (added with pybind11v3) when writing
|
|
new bindings. See :ref:`native_enum` for more information.
|
|
|
|
Let's suppose that we have an example class that contains internal types
|
|
like enumerations, e.g.:
|
|
|
|
.. code-block:: cpp
|
|
|
|
struct Pet {
|
|
enum Kind {
|
|
Dog = 0,
|
|
Cat
|
|
};
|
|
|
|
struct Attributes {
|
|
float age = 0;
|
|
};
|
|
|
|
Pet(const std::string &name, Kind type) : name(name), type(type) { }
|
|
|
|
std::string name;
|
|
Kind type;
|
|
Attributes attr;
|
|
};
|
|
|
|
The binding code for this example looks as follows:
|
|
|
|
.. code-block:: cpp
|
|
|
|
py::class_<Pet> pet(m, "Pet");
|
|
|
|
pet.def(py::init<const std::string &, Pet::Kind>())
|
|
.def_readwrite("name", &Pet::name)
|
|
.def_readwrite("type", &Pet::type)
|
|
.def_readwrite("attr", &Pet::attr);
|
|
|
|
py::enum_<Pet::Kind>(pet, "Kind")
|
|
.value("Dog", Pet::Kind::Dog)
|
|
.value("Cat", Pet::Kind::Cat)
|
|
.export_values();
|
|
|
|
py::class_<Pet::Attributes>(pet, "Attributes")
|
|
.def(py::init<>())
|
|
.def_readwrite("age", &Pet::Attributes::age);
|
|
|
|
|
|
To ensure that the nested types ``Kind`` and ``Attributes`` are created within the scope of ``Pet``, the
|
|
``pet`` ``py::class_`` instance must be supplied to the :class:`enum_` and ``py::class_``
|
|
constructor. The :func:`enum_::export_values` function exports the enum entries
|
|
into the parent scope, which should be skipped for newer C++11-style strongly
|
|
typed enums.
|
|
|
|
.. code-block:: pycon
|
|
|
|
>>> p = Pet("Lucy", Pet.Cat)
|
|
>>> p.type
|
|
Kind.Cat
|
|
>>> int(p.type)
|
|
1L
|
|
|
|
The entries defined by the enumeration type are exposed in the ``__members__`` property:
|
|
|
|
.. code-block:: pycon
|
|
|
|
>>> Pet.Kind.__members__
|
|
{'Dog': Kind.Dog, 'Cat': Kind.Cat}
|
|
|
|
The ``name`` property returns the name of the enum value as a unicode string.
|
|
|
|
.. note::
|
|
|
|
It is also possible to use ``str(enum)``, however these accomplish different
|
|
goals. The following shows how these two approaches differ.
|
|
|
|
.. code-block:: pycon
|
|
|
|
>>> p = Pet("Lucy", Pet.Cat)
|
|
>>> pet_type = p.type
|
|
>>> pet_type
|
|
Pet.Cat
|
|
>>> str(pet_type)
|
|
'Pet.Cat'
|
|
>>> pet_type.name
|
|
'Cat'
|
|
|
|
.. note::
|
|
|
|
When the special tag ``py::arithmetic()`` is specified to the ``enum_``
|
|
constructor, pybind11 creates an enumeration that also supports rudimentary
|
|
arithmetic and bit-level operations like comparisons, and, or, xor, negation,
|
|
etc.
|
|
|
|
.. code-block:: cpp
|
|
|
|
py::enum_<Pet::Kind>(pet, "Kind", py::arithmetic())
|
|
...
|
|
|
|
By default, these are omitted to conserve space.
|
|
|
|
.. warning::
|
|
|
|
Contrary to Python customs, enum values from the wrappers should not be compared using ``is``, but with ``==`` (see `#1177 <https://github.com/pybind/pybind11/issues/1177>`_ for background).
|