pybind11 v2.6.1 Release Notes

Release Date: 2020-11-12 // almost 3 years ago
    • py::exec, py::eval, and py::eval_file now add the builtins module as " __builtins__" to their globals argument, better matching exec and eval in pure Python. #2616
    • ๐ŸŽ setup_helpers will no longer set a minimum macOS version higher than the current version. #2622
    • ๐Ÿ‘ Allow deleting static properties. #2629
    • Seal a leak in def_buffer, cleaning up the capture object after the class_ object goes out of scope.
    • pybind11_INCLUDE_DIRS was incorrect, potentially causing a regression if it was expected to include PYTHON_INCLUDE_DIRS (please use targets instead). #2636
    • โž• Added parameter names to the py::enum_ constructor and methods, avoiding arg0 in the generated docstrings. #2637
    • โž• Added needs_recompile optional function to the ParallelCompiler helper, to allow a recompile to be skipped based on a user-defined function. #2643

Previous changes from v2.6.0

  • ๐Ÿ†• New features:

    • ๐Ÿ‘ Keyword-only arguments supported in Python 2 or 3 with py::kw_only(). #2100
    • ๐Ÿ‘ Positional-only arguments supported in Python 2 or 3 with py::pos_only(). #2459
    • py::is_final() class modifier to block subclassing (CPython only). #2151
    • โž• Added py::prepend(), allowing a function to be placed at the beginning of the overload chain. #1131
    • Access to the type object now provided with py::type::of<T>() and py::type::of(h). #2364
    • ๐Ÿ‘ Perfect forwarding support for methods. #2048
    • Added py::error_already_set::discard_as_unraisable(). #2372
    • py::hash is now public. #2217
    • py::class_<union_type> is now supported. Note that writing to one data member of the union and reading another (type punning) is UB in C++. Thus pybind11-bound enums should never be used for such conversions. #2320.
    • Classes now check local scope when registering members, allowing a subclass to have a member with the same name as a parent (such as an enum). #2335

    Code correctness features:

    • Error now thrown when __init__ is forgotten on subclasses. #2152
    • Throw error if conversion to a pybind11 type if the Python object isn't a valid instance of that type, such as py::bytes(o) when py::object o isn't a bytes instance. #2349
    • Throw if conversion to str fails. #2477

    API changes:

    • py::module was renamed py::module_ to avoid issues with C++20 when used unqualified, but an alias py::module is provided for backward compatibility. #2489
    • ๐Ÿ—„ Public constructors for py::module_ have been deprecated; please use pybind11::module_::create_extension_module if you were using the public constructor (fairly rare after PYBIND11_MODULE was introduced). #2552
    • PYBIND11_OVERLOAD* macros and get_overload function replaced by correctly-named PYBIND11_OVERRIDE* and get_override, fixing inconsistencies in the presence of a closing ; in these macros. get_type_overload is deprecated. #2325

    ๐Ÿ— Packaging / building improvements:

    • ๐Ÿ“ฆ The Python package was reworked to be more powerful and useful. #2433
      • build-setuptools is easier thanks to a new pybind11.setup_helpers module, which provides utilities to use setuptools with pybind11. It can be used via PEP 518, setup_requires, or by directly importing or copying into your project.
      • CMake configuration files are now included in the Python package. Use pybind11.get_cmake_dir() or python -m pybind11 --cmakedir to get the directory with the CMake configuration files, or include the site-packages location in your CMAKE_MODULE_PATH. Or you can use the new pybind11[global] extra when you install pybind11, which installs the CMake files and headers into your base environment in the standard location.
      • pybind11-config is another way to write python -m pybind11 if you have your PATH set up.
      • Added external typing support to the helper module, code from import pybind11 can now be type checked. #2588
    • Minimum CMake required increased to 3.4. #2338 and #2370
      • Full integration with CMake's C++ standard system and compile features replaces PYBIND11_CPP_STANDARD.
      • Generated config file is now portable to different Python/compiler/CMake versions.
      • Virtual environments prioritized if PYTHON_EXECUTABLE is not set (venv, virtualenv, and conda) (similar to the new FindPython mode).
      • Other CMake features now natively supported, like CMAKE_INTERPROCEDURAL_OPTIMIZATION, set(CMAKE_CXX_VISIBILITY_PRESET hidden).
      • CUDA as a language is now supported.
      • Helper functions pybind11_strip, pybind11_extension, pybind11_find_import added, see cmake/index.
      • Optional find-python-mode and nopython-mode with CMake. #2370
    • Uninstall target added. #2265 and #2346
    • โž• pybind11_add_module() now accepts an optional OPT_SIZE flag that switches the binding target to size-based optimization if the global build type can not always be fixed to MinSizeRel (except in debug mode, where optimizations remain disabled). MinSizeRel or this flag reduces binary size quite substantially (~25% on some platforms). #2463

    ๐Ÿ›  Smaller or developer focused features and fixes:

    • ๐Ÿšš Moved to a new repo, pybind11-mkdoc. There are no longer submodules in the main repo.
    • ๐Ÿ“š py::memoryview segfault fix and update, with new py::memoryview::from_memory in Python 3, and documentation. #2223
    • ๐Ÿ›  Fix for buffer_info on Python 2. #2503
    • If __eq__ defined but not __hash__, __hash__ is now set to None. #2291
    • py::ellipsis now also works on Python 2. #2360
    • ๐Ÿ‘ Pointer to std::tuple & std::pair supported in cast. #2334
    • ๐Ÿ›  Small fixes in NumPy support. py::array now uses py::ssize_t as first argument type. #2293
    • โž• Added missing signature for py::array. #2363
    • unchecked_mutable_reference has access to operator () and [] when const. #2514
    • ๐Ÿ‘ py::vectorize is now supported on functions that return void. #1969
    • py::capsule supports get_pointer and set_pointer. #1131
    • ๐Ÿ›  Fix crash when different instances share the same pointer of the same type. #2252
    • ๐Ÿ›  Fix for py::len not clearing Python's error state when it fails and throws. #2575
    • ๐Ÿ›  Bugfixes related to more extensive testing, new GitHub Actions CI. #2321
    • ๐Ÿ› Bug in timezone issue in Eastern hemisphere midnight fixed. #2438
    • std::chrono::time_point now works when the resolution is not the same as the system. #2481
    • ๐Ÿ› Bug fixed where py::array_t could accept arrays that did not match the requested ordering. #2484
    • ๐Ÿšš Avoid a segfault on some compilers when types are removed in Python. #2564
    • py::arg::none() is now also respected when passing keyword arguments. #2611
    • ๐Ÿ PyPy fixes, PyPy 7.3.x now supported, including PyPy3. (Known issue with PyPy2 and Windows #2596). #2146
    • ๐ŸŽ CPython 3.9.0 workaround for undefined behavior (macOS segfault). #2576
    • โš  CPython 3.9 warning fixes. #2253
    • ๐Ÿ‘Œ Improved C++20 support, now tested in CI. #2489 #2599
    • ๐Ÿ‘Œ Improved but still incomplete debug Python interpreter support. #2025
    • โœ… NVCC (CUDA 11) now supported and tested in CI. #2461
    • โœ… NVIDIA PGI compilers now supported and tested in CI. #2475
    • At least Intel 18 now explicitly required when compiling with Intel. #2577
    • ๐Ÿ’… Extensive style checking in CI, with pre-commit support. Code modernization, checked by clang-tidy.
    • ๐Ÿ“„ Expanded docs, including new main page, new installing section, and CMake helpers page, along with over a dozen new sections on existing pages.
    • ๐Ÿ“„ In GitHub, new docs for contributing and new issue templates.