Releases: pybind/pybind11
Version 2.7.0
New features:
- Enable
py::implicitly_convertible<py::none, ...>forpy::class_-wrapped types. #3059 - Allow function pointer extraction from overloaded functions. #2944
- NumPy: added
.char_()to type which gives the NumPy publiccharresult, which also distinguishes types by bit length (unlike.kind()). #2864 - Add
pybind11::bytearrayto manipulatebytearraysimilar tobytes. #2799 pybind11/stl/filesystem.hregisters a type caster that, on C++17/Python 3.6+, convertsstd::filesystem::pathtopathlib.Pathand anyos.PathLiketostd::filesystem::path. #2730- A
PYBIND11_VERSION_HEXdefine was added, similar toPY_VERSION_HEX. #3120
Changes:
py::strchanged to exclusively holdPyUnicodeObject. Previouslypy::strcould
also holdbytes, which is probably surprising, was never documented, and can mask bugs (e.g. accidental use ofpy::strinstead ofpy::bytes). #2409- Add a safety guard to ensure that the Python GIL is held when C++ calls back into Python via
object_api<>::operator()(e.g.py::function__call__). (This feature is available for Python 3.6+ only.) #2919 - Catch a missing
selfargument in calls to__init__(). #2914 - Use
std::string_viewif available to avoid a copy when passing an object to astd::ostream. #3042 - An important warning about thread safety was added to the
iostream.hdocumentation; attempts to makepy::scoped_ostream_redirectthread safe have been removed, as it was only partially effective. #2995
Fixes:
- Performance: avoid unnecessary strlen calls. #3058
- Fix auto-generated documentation string when using
const Tinpyarray_t. #3020 - Unify error messages thrown by
simple_collector/unpacking_collector. #3013 pybind11::builtin_exceptionis now explicitly exported, which means the types included/defined in different modules are identical, and exceptions raised in different modules can be caught correctly. The documentation was updated to explain that custom exceptions that are used across module boundaries need to be explicitly exported as well. #2999- Fixed exception when printing UTF-8 to a
scoped_ostream_redirect. #2982 - Pickle support enhancement:
setstateimplementation will attempt tosetattr__dict__only if the unpickleddictobject is not empty, to not force use ofpy::dynamic_attr()unnecessarily. #2972 - Allow negative timedelta values to roundtrip. #2870
- Fix unchecked errors could potentially swallow signals/other exceptions. #2863
- Add null pointer check with
std::localtime. #2846 - Fix the
weakrefconstructor frompy::objectto create a newweakrefon conversion. #2832 - Avoid relying on exceptions in C++17 when getting a
shared_ptrholder from ashared_from_thisclass. #2819 - Allow the codec's exception to be raised instead of
RuntimeErrorwhen casting frompy::strtostd::string. #2903
Build system improvements:
- In
setup_helpers.py, test for platforms that have some multiprocessing features but lack semaphores, whichParallelCompilerequires. #3043 - Fix
pybind11_INCLUDE_DIRin caseCMAKE_INSTALL_INCLUDEDIRis absolute. #3005 - Fix bug not respecting
WITH_SOABIorWITHOUT_SOABIto CMake. #2938 - Fix the default
Pybind11Extensioncompilation flags with a Mingw64 python. #2921 - Clang on Windows: do not pass
/MP(ignored flag). #2824 pybind11.setup_helpers.intree_extensionscan be used to generatePybind11Extensioninstances from cpp files placed in the Python
package source tree. #2831
Backend and tidying up:
- Enable clang-tidy performance, readability, and modernization checks throughout the codebase to enforce best coding practices. #3046, #3049, #3051, #3052, #3080, and #3094
- Checks for common misspellings were added to the pre-commit hooks. #3076
- Changed
Werrorto stricterWerror-allfor Intel compiler and fixed minor issues. #2948 - Fixed compilation with GCC < 5 when the user defines
_GLIBCXX_USE_CXX11_ABI. #2956 - Added nox support for easier local testing and linting of contributions. #3101 and #3121
- Avoid RTD style issue with docutils 0.17+. #3119
- Support pipx run, such as
pipx run pybind11 --includefor a quick compile. #3117
Version 2.6.2
Minor missing functionality added:
- enum: add missing Enum.value property. #2739
- Allow thread termination to be avoided during shutdown for CPython 3.7+ via
.disarmforgil_scoped_acquire/gil_scoped_release. #2657
Fixed or improved behavior in a few special cases:
- Fix bug where the constructor of
objectsubclasses would not throw on being passed a Python object of the wrong type. #2701 - The
type_casterfor integers does not convert Python objects with__int__anymore withnoconvertor during the first round of trying overloads. #2698 - When casting to a C++ integer,
__index__is always called and not considered as conversion, consistent with Python 3.8+. #2801
Build improvements:
- Setup helpers:
extra_compile_argsandextra_link_argsautomatically set by Pybind11Extension are now prepended, which allows them to be overridden by user-setextra_compile_argsandextra_link_args. #2808 - Setup helpers: Don't trigger unused parameter warning. #2735
- CMake: Support running with
--warn-uninitializedactive. #2806 - CMake: Avoid error if included from two submodule directories. #2804
- CMake: Fix
STATIC/SHAREDbeing ignored in FindPython mode. #2796 - CMake: Respect the setting for
CMAKE_CXX_VISIBILITY_PRESETif defined. #2793 - CMake: Fix issue with FindPython2/FindPython3 not working with
pybind11::embed. #2662 - CMake: mixing local and installed pybind11's would prioritize the installed one over the local one (regression in 2.6.0). #2716
Bug fixes:
- Fixed segfault in multithreaded environments when using
scoped_ostream_redirect. #2675 - Leave docstring unset when all docstring-related options are disabled, rather than set an empty string. #2745
- The module key in builtins that pybind11 uses to store its internals changed from std::string to a python str type (more natural on Python 2, no change on Python 3). #2814
- Fixed assertion error related to unhandled (later overwritten) exception in CPython 3.8 and 3.9 debug builds. #2685
- Fix
py::gil_scoped_acquireassert with CPython 3.9 debug build. #2683 - Fix issue with a test failing on PyTest 6.2. #2741
Warning fixes:
- Fix warning modifying constructor parameter 'flag' that shadows a field of 'set_flag'
[-Wshadow-field-in-constructor-modified]. #2780 - Suppressed some deprecation warnings about old-style
__init__/__setstate__in the tests. #2759
Valgrind work:
- Fix invalid access when calling a pybind11
__init__on a non-pybind11 class instance. #2755 - Fixed various minor memory leaks in pybind11's test suite. #2758
- Resolved memory leak in cpp_function initialization when exceptions occurred. #2756
- Added a Valgrind build, checking for leaks and memory-related UB, to CI. #2746
Compiler support:
Version 2.6.1
py::exec,py::eval, andpy::eval_filenow add the builtins module as"__builtins__"to theirglobalsargument, better matchingexecandevalin pure Python. #2616setup_helperswill 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 thecaptureobject after theclass_object goes out of scope.
#2634 pybind11_INCLUDE_DIRSwas incorrect, potentially causing a regression if it was expected to includePYTHON_INCLUDE_DIRS(please use targets instead). #2636- Added parameter names to the
py::enum_constructor and methods, avoidingarg0in the generated docstrings. #2637 - Added
needs_recompileoptional function to theParallelCompilerhelper, to allow a recompile to be skipped based on a user-defined function. #2643
Version 2.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>()andpy::type::of(h). #2364 - Perfect forwarding support for methods. #2048
- Added
py::error_already_set::discard_as_unraisable(). #2372 py::hashis now public. #2217py::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)whenpy::object oisn't a bytes instance. #2349 - Throw if conversion to
strfails. #2477
API changes:
py::modulewas renamedpy::module_to avoid issues with C++20 when used unqualified, but an aliaspy::moduleis provided for backward compatibility. #2489- Public constructors for
py::module_have been deprecated; please usepybind11::module_::create_extension_moduleif you were using the public constructor (fairly rare afterPYBIND11_MODULEwas introduced). #2552 PYBIND11_OVERLOAD*macros andget_overloadfunction replaced by correctly-namedPYBIND11_OVERRIDE*andget_override, fixing inconsistencies in the presence of a closing;in these macros.get_type_overloadis deprecated. #2325
Packaging / building improvements:
- The Python package was reworked to be more powerful and useful. #2433
build-setuptoolsis easier thanks to a newpybind11.setup_helpersmodule, which provides utilities to use setuptools with pybind11. It can be used via PEP 518,setup_requires, or by directly importing or copyingsetup_helpers.pyinto your project.- CMake configuration files are now included in the Python package. Use
pybind11.get_cmake_dir()orpython -m pybind11 --cmakedirto get the directory with the CMake configuration files, or include the site-packages location in yourCMAKE_MODULE_PATH. Or you can use the newpybind11[global]extra when you installpybind11, which installs the CMake files and headers into your base environment in the standard location. pybind11-configis another way to writepython -m pybind11if you have your PATH set up.- Added external typing support to the helper module, code from
import pybind11can 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_EXECUTABLEis not set (venv,virtualenv, andconda) (similar to the new FindPython mode). - Other CMake features now natively supported, like
CMAKE_INTERPROCEDURAL_OPTIMIZATION,set(CMAKE_CXX_VISIBILITY_PRESET hidden). CUDAas a language is now supported.- Helper functions
pybind11_strip,pybind11_extension,pybind11_find_importadded, seecmake/index. - Optional
find-python-modeandnopython-modewith CMake. #2370
- Full integration with CMake's C++ standard system and compile features replaces
- Uninstall target added. #2265 and #2346
pybind11_add_module()now accepts an optionalOPT_SIZEflag that switches the binding target to size-based optimization if the global build type can not always be fixed toMinSizeRel(except in debug mode, where optimizations remain disabled).MinSizeRelor this flag reduces binary size quite substantially (~25% on some platforms). #2463
Smaller or developer focused features and fixes:
- Moved
mkdoc.pyto a new repo, pybind11-mkdoc. There are no longer submodules in the main repo. py::memoryviewsegfault fix and update, with newpy::memoryview::from_memoryin Python 3, and documentation. #2223- Fix for
buffer_infoon Python 2. #2503 - If
__eq__defined but not__hash__,__hash__is now set toNone. #2291 py::ellipsisnow also works on Python 2. #2360- Pointer to
std::tuple&std::pairsupported in cast. #2334 - Small fixes in NumPy support.
py::arraynow usespy::ssize_tas first argument type. #2293 - Added missing signature for
py::array. #2363 unchecked_mutable_referencehas access to operator()and[]when const. #2514py::vectorizeis now supported on functions that return void. #1969py::capsulesupportsget_pointerandset_pointer. #1131- Fix crash when different instances share the same pointer of the same type. #2252
- Fix for
py::lennot 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_pointnow works when the resolution is not the same as the system. #2481- Bug fixed where
py::array_tcould 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.
Version 2.6.0 RC 3
Next release candidate.
- Factory constructor scope fix
- Support for PyPy3 on Windows 32, added to CI
- Fixes for C++20, added to CI for Clang, GCC, and MSVC 2019
- Black formatting for all Python code
- Allow ABI string overrides from 2.4 (advanced)
Version 2.6.0 RC 2
Next release candidate. Changes since RC 1:
Fixed:
- Python 3.9.0 bug workaround implemented
- Better support in CMake for packing and cross-compiling
- Fix for failing
py::lenleaving error state set - Intel 18+ explicitly required, an issue with Intel compilers fixed
- Custom ipo flags disabled with
RelWithDebInfo(useCMAKE_INTERPROCEDURAL_OPTIMIZATIONfor more control) - Possible duplicate linker flags fixed in
setup_helpers - Changes to
py::module_constructor are no longer provisional.
New features:
- Static typing support for
import pybind11
Version 2.6.0 RC 1
This is the first release candidate for pybind11 2.6.0. Please see the new features in the changelog, such as revamped CMake and setuptools support, keyword and positional argument support, and a long list of features, fixes, and improvements. Full Python 3.9 support and enhanced C++20 support.
Known issues:
py::module_direct construction provisionally deprecated- Removing registered types can cause a segfault - old issue exposed by recent test additions; fix incoming
- On Python 3.9.0 and macOS, pybind11 may segfault when closing the interpreter after running the test suite
Version 2.6.0 Beta 1
v2.6.0 beta release.