diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40209adb4..27d9df248 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -601,11 +601,11 @@ jobs: fail-fast: false matrix: centos: - - 7 # GCC 4.8 - - 8 + - centos7 # GCC 4.8 + - stream8 name: "🐍 3 • CentOS ${{ matrix.centos }} • x64" - container: "centos:${{ matrix.centos }}" + container: "quay.io/centos/centos:${{ matrix.centos }}" steps: - uses: actions/checkout@v2 @@ -620,22 +620,11 @@ jobs: run: | python3 -m pip install cmake -r tests/requirements.txt - - name: VAR_BUILD_TYPE 7 - if: matrix.centos == 7 - run: echo MinSizeRel > VAR_BUILD_TYPE - - # Using Release to avoid segfault that appeared around 2021-06-04, - # apparently when the gcc version changed from 8.3 to 8.4. - - name: VAR_BUILD_TYPE 8 - if: matrix.centos == 8 - run: echo Release > VAR_BUILD_TYPE - - # Temporally disabling EIGEN due to SSL issue in CentOS 7 - name: Configure shell: bash run: > cmake -S . -B build - -DCMAKE_BUILD_TYPE=$(cat VAR_BUILD_TYPE) + -DCMAKE_BUILD_TYPE=MinSizeRel -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON diff --git a/docs/changelog.rst b/docs/changelog.rst index c05e7d3c5..63c7f41d8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,65 @@ Changelog Starting with version 1.8.0, pybind11 releases use a `semantic versioning `_ policy. +IN DEVELOPMENT +-------------- + +Changes will be added here periodically. + + +Version 2.9.1 (Feb 2, 2022) +--------------------------- + +Changes: + +* If possible, attach Python exception with ``py::raise_from`` to ``TypeError`` + when casting from C++ to Python. This will give additional info if Python + exceptions occur in the caster. Adds a test case of trying to convert a set + from C++ to Python when the hash function is not defined in Python. + `#3605 `_ + +* Add a mapping of C++11 nested exceptions to their Python exception + equivalent using ``py::raise_from``. This attaches the nested exceptions in + Python using the ``__cause__`` field. + `#3608 `_ + +* Propagate Python exception traceback using ``raise_from`` if a pybind11 + function runs out of overloads. + `#3671 `_ + +* ``py::multiple_inheritance`` is now only needed when C++ bases are hidden + from pybind11. + `#3650 `_ and + `#3659 `_ + + +Bug fixes: + +* Remove a boolean cast in ``numpy.h`` that causes MSVC C4800 warnings when + compiling against Python 3.10 or newer. + `#3669 `_ + +* Render ``py::bool_`` and ``py::float_`` as ``bool`` and ``float`` + respectively. + `#3622 `_ + +Build system improvements: + +* Fix CMake extension suffix computation on Python 3.10+. + `#3663 `_ + +* Allow ``CMAKE_ARGS`` to override CMake args in pybind11's own ``setup.py``. + `#3577 `_ + +* Remove a few deprecated c-headers. + `#3610 `_ + +* More uniform handling of test targets. + `#3590 `_ + +* Add clang-tidy readability check to catch potentially swapped function args. + `#3611 `_ + Version 2.9.0 (Dec 28, 2021) ---------------------------- diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index b3513da83..d9f838236 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -10,12 +10,12 @@ #pragma once #define PYBIND11_VERSION_MAJOR 2 -#define PYBIND11_VERSION_MINOR 9 -#define PYBIND11_VERSION_PATCH 0 +#define PYBIND11_VERSION_MINOR 10 +#define PYBIND11_VERSION_PATCH 0.dev1 // Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html // Additional convention: 0xD = dev -#define PYBIND11_VERSION_HEX 0x02090000 +#define PYBIND11_VERSION_HEX 0x020A00D1 #define PYBIND11_NAMESPACE_BEGIN(name) namespace name { #define PYBIND11_NAMESPACE_END(name) } diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index f36add66e..2dd08a42e 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -201,7 +201,9 @@ struct type_info { void *get_buffer_data = nullptr; void *(*module_local_load)(PyObject *, const type_info *) = nullptr; /* A simple type never occurs as a (direct or indirect) parent - * of a class that makes use of multiple inheritance */ + * of a class that makes use of multiple inheritance. + * A type can be simple even if it has non-simple ancestors as long as it has no descendants. + */ bool simple_type : 1; /* True if there is no multiple inheritance in this type's inheritance tree */ bool simple_ancestors : 1; diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 8e83b506e..95a743ace 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -170,10 +170,10 @@ struct npy_api { } bool PyArray_Check_(PyObject *obj) const { - return (bool) PyObject_TypeCheck(obj, PyArray_Type_); + return PyObject_TypeCheck(obj, PyArray_Type_) != 0; } bool PyArrayDescr_Check_(PyObject *obj) const { - return (bool) PyObject_TypeCheck(obj, PyArrayDescr_Type_); + return PyObject_TypeCheck(obj, PyArrayDescr_Type_) != 0; } unsigned int (*PyArray_GetNDArrayCFeatureVersion_)(); diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 8fe26a845..8bacef09e 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -990,6 +990,14 @@ protected: } append_note_if_missing_header_is_suspected(msg); +#if PY_VERSION_HEX >= 0x03030000 + // Attach additional error info to the exception if supported + if (PyErr_Occurred()) { + // #HelpAppreciated: unit test coverage for this branch. + raise_from(PyExc_TypeError, msg.c_str()); + return nullptr; + } +#endif PyErr_SetString(PyExc_TypeError, msg.c_str()); return nullptr; } @@ -1209,13 +1217,14 @@ protected: if (rec.bases.size() > 1 || rec.multiple_inheritance) { mark_parents_nonsimple(tinfo->type); tinfo->simple_ancestors = false; - tinfo->simple_type = false; } else if (rec.bases.size() == 1) { - auto parent_tinfo = get_type_info((PyTypeObject *) rec.bases[0].ptr()); - tinfo->simple_ancestors = parent_tinfo->simple_ancestors; - // a child of a non-simple type can never be a simple type - tinfo->simple_type = parent_tinfo->simple_type; + auto *parent_tinfo = get_type_info((PyTypeObject *) rec.bases[0].ptr()); + assert(parent_tinfo != nullptr); + bool parent_simple_ancestors = parent_tinfo->simple_ancestors; + tinfo->simple_ancestors = parent_simple_ancestors; + // The parent can no longer be a simple type if it has MI and has a child + parent_tinfo->simple_type = parent_tinfo->simple_type && parent_simple_ancestors; } if (rec.module_local) { diff --git a/pybind11/_version.py b/pybind11/_version.py index 6627d4c7e..7519ac903 100644 --- a/pybind11/_version.py +++ b/pybind11/_version.py @@ -8,5 +8,5 @@ def _to_int(s): return s -__version__ = "2.9.0" +__version__ = "2.10.0.dev1" version_info = tuple(_to_int(s) for s in __version__.split(".")) diff --git a/setup.cfg b/setup.cfg index 95963d2f8..317c44bbf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,8 +31,15 @@ keywords = C++11 Python bindings +project_urls = + Documentation = https://pybind11.readthedocs.io/ + Bug Tracker = https://github.com/pybind/pybind11/issues + Discussions = https://github.com/pybind/pybind11/discussions + Changelog = https://pybind11.readthedocs.io/en/latest/changelog.html + Chat = https://gitter.im/pybind/Lobby + [options] -python_requires = >=2.7, !=3.0, !=3.1, !=3.2, !=3.3, !=3.4 +python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* zip_safe = False [bdist_wheel] diff --git a/setup.py b/setup.py index a2326287d..f83837919 100644 --- a/setup.py +++ b/setup.py @@ -45,8 +45,11 @@ def build_expected_version_hex(matches): if serial is None: msg = 'Invalid PYBIND11_VERSION_PATCH: "{}"'.format(patch_level_serial) raise RuntimeError(msg) - return "0x{:02x}{:02x}{:02x}{}{:x}".format( - major, minor, patch, level[:1].upper(), serial + return ( + "0x" + + "{:02x}{:02x}{:02x}{}{:x}".format( + major, minor, patch, level[:1], serial + ).upper() ) @@ -146,6 +149,13 @@ with remove_output("pybind11/include", "pybind11/share"): "-DBUILD_TESTING=OFF", "-DPYBIND11_NOPYTHON=ON", ] + if "CMAKE_ARGS" in os.environ: + fcommand = [ + c + for c in os.environ["CMAKE_ARGS"].split() + if "DCMAKE_INSTALL_PREFIX" not in c + ] + cmd += fcommand cmake_opts = dict(cwd=DIR, stdout=sys.stdout, stderr=sys.stderr) subprocess.check_call(cmd, **cmake_opts) subprocess.check_call(["cmake", "--install", tmpdir], **cmake_opts) diff --git a/tests/test_multiple_inheritance.cpp b/tests/test_multiple_inheritance.cpp index 29ee018c7..7424ce7c8 100644 --- a/tests/test_multiple_inheritance.cpp +++ b/tests/test_multiple_inheritance.cpp @@ -235,7 +235,7 @@ TEST_SUBMODULE(multiple_inheritance, m) { // - functions are get_{base}_{var}, return {var} struct MVB { MVB() = default; - MVB(const MVB&) = default; + MVB(const MVB &) = default; virtual ~MVB() = default; int b = 1; diff --git a/tests/test_multiple_inheritance.py b/tests/test_multiple_inheritance.py index 71741b925..abdf25d60 100644 --- a/tests/test_multiple_inheritance.py +++ b/tests/test_multiple_inheritance.py @@ -472,3 +472,25 @@ def test_pr3635_diamond_f(): assert o.get_f_e() == 5 assert o.get_f_f() == 6 + + +def test_python_inherit_from_mi(): + """Tests extending a Python class from a single inheritor of a MI class""" + + class PyMVF(m.MVF): + g = 7 + + def get_g_g(self): + return self.g + + o = PyMVF() + + assert o.b == 1 + assert o.c == 2 + assert o.d0 == 3 + assert o.d1 == 4 + assert o.e == 5 + assert o.f == 6 + assert o.g == 7 + + assert o.get_g_g() == 7 diff --git a/tests/test_numpy_dtypes.py b/tests/test_numpy_dtypes.py index 06e578329..0098eccb8 100644 --- a/tests/test_numpy_dtypes.py +++ b/tests/test_numpy_dtypes.py @@ -32,8 +32,8 @@ def dt_fmt(): e = "<" if byteorder == "little" else ">" return ( "{{'names':['bool_','uint_','float_','ldbl_']," - " 'formats':['?','" + e + "u4','" + e + "f4','" + e + "f{}']," - " 'offsets':[0,4,8,{}], 'itemsize':{}}}" + "'formats':['?','" + e + "u4','" + e + "f4','" + e + "f{}']," + "'offsets':[0,4,8,{}],'itemsize':{}}}" ) @@ -46,7 +46,7 @@ def simple_dtype_fmt(): def packed_dtype_fmt(): from sys import byteorder - return "[('bool_', '?'), ('uint_', '{e}u4'), ('float_', '{e}f4'), ('ldbl_', '{e}f{}')]".format( + return "[('bool_','?'),('uint_','{e}u4'),('float_','{e}f4'),('ldbl_','{e}f{}')]".format( np.dtype("longdouble").itemsize, e="<" if byteorder == "little" else ">" ) @@ -77,7 +77,7 @@ def partial_nested_fmt(): partial_size = partial_ld_off + ld.itemsize partial_end_padding = partial_size % np.dtype("uint64").alignment partial_nested_size = partial_nested_off * 2 + partial_size + partial_end_padding - return "{{'names':['a'], 'formats':[{}], 'offsets':[{}], 'itemsize':{}}}".format( + return "{{'names':['a'],'formats':[{}],'offsets':[{}],'itemsize':{}}}".format( partial_dtype_fmt(), partial_nested_off, partial_nested_size ) @@ -123,25 +123,25 @@ def test_dtype(simple_dtype): e = "<" if byteorder == "little" else ">" - assert m.print_dtypes() == [ + assert [x.replace(" ", "") for x in m.print_dtypes()] == [ simple_dtype_fmt(), packed_dtype_fmt(), - "[('a', {}), ('b', {})]".format(simple_dtype_fmt(), packed_dtype_fmt()), + "[('a',{}),('b',{})]".format(simple_dtype_fmt(), packed_dtype_fmt()), partial_dtype_fmt(), partial_nested_fmt(), - "[('a', 'S3'), ('b', 'S3')]", + "[('a','S3'),('b','S3')]", ( - "{{'names':['a','b','c','d'], " - + "'formats':[('S4', (3,)),('" + "{{'names':['a','b','c','d']," + + "'formats':[('S4',(3,)),('" + e - + "i4', (2,)),('u1', (3,)),('" + + "i4',(2,)),('u1',(3,)),('" + e - + "f4', (4, 2))], " - + "'offsets':[0,12,20,24], 'itemsize':56}}" + + "f4',(4,2))]," + + "'offsets':[0,12,20,24],'itemsize':56}}" ).format(e=e), - "[('e1', '" + e + "i8'), ('e2', 'u1')]", - "[('x', 'i1'), ('y', '" + e + "u8')]", - "[('cflt', '" + e + "c8'), ('cdbl', '" + e + "c16')]", + "[('e1','" + e + "i8'),('e2','u1')]", + "[('x','i1'),('y','" + e + "u8')]", + "[('cflt','" + e + "c8'),('cdbl','" + e + "c16')]", ] d1 = np.dtype( @@ -238,7 +238,7 @@ def test_recarray(simple_dtype, packed_dtype): ] arr = m.create_rec_partial(3) - assert str(arr.dtype) == partial_dtype_fmt() + assert str(arr.dtype).replace(" ", "") == partial_dtype_fmt() partial_dtype = arr.dtype assert "" not in arr.dtype.fields assert partial_dtype.itemsize > simple_dtype.itemsize @@ -246,7 +246,7 @@ def test_recarray(simple_dtype, packed_dtype): assert_equal(arr, elements, packed_dtype) arr = m.create_rec_partial_nested(3) - assert str(arr.dtype) == partial_nested_fmt() + assert str(arr.dtype).replace(" ", "") == partial_nested_fmt() assert "" not in arr.dtype.fields assert "" not in arr.dtype.fields["a"][0].fields assert arr.dtype.itemsize > partial_dtype.itemsize @@ -285,12 +285,12 @@ def test_array_array(): e = "<" if byteorder == "little" else ">" arr = m.create_array_array(3) - assert str(arr.dtype) == ( - "{{'names':['a','b','c','d'], " - + "'formats':[('S4', (3,)),('" + assert str(arr.dtype).replace(" ", "") == ( + "{{'names':['a','b','c','d']," + + "'formats':[('S4',(3,)),('" + e - + "i4', (2,)),('u1', (3,)),('{e}f4', (4, 2))], " - + "'offsets':[0,12,20,24], 'itemsize':56}}" + + "i4',(2,)),('u1',(3,)),('{e}f4',(4,2))]," + + "'offsets':[0,12,20,24],'itemsize':56}}" ).format(e=e) assert m.print_array_array(arr) == [ "a={{A,B,C,D},{K,L,M,N},{U,V,W,X}},b={0,1}," diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index 9e2fd2b40..0b4e21cce 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -110,7 +110,7 @@ if(NOT DEFINED PYTHON_MODULE_EXTENSION) execute_process( COMMAND "${${_Python}_EXECUTABLE}" "-c" - "from distutils import sysconfig as s;print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" + "import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR OUTPUT_STRIP_TRAILING_WHITESPACE)