diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 161171e68..aa6058c1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,7 @@ jobs: - 2.7 - 3.5 - 3.8 + - 3.9 - pypy2 - pypy3 @@ -32,34 +33,33 @@ jobs: # We support three optional keys: args (both build), args1 (first # build), and args2 (second build). include: + # Just add a key - runs-on: ubuntu-latest python: 3.6 arch: x64 args: > -DPYBIND11_FINDPYTHON=ON + - runs-on: windows-latest + python: 3.6 + arch: x64 + args: > + -DPYBIND11_FINDPYTHON=ON + - runs-on: ubuntu-latest + python: 3.8 + arch: x64 + args: > + -DPYBIND11_FINDPYTHON=ON + + # New runs - runs-on: windows-2016 python: 3.7 arch: x86 args2: > -DCMAKE_CXX_FLAGS="/permissive- /EHsc /GR" - - runs-on: windows-latest - python: 3.6 - arch: x64 - args: > - -DPYBIND11_FINDPYTHON=ON - runs-on: windows-latest python: 3.7 arch: x64 - - runs-on: ubuntu-latest - python: 3.9-dev - arch: x64 - - runs-on: macos-latest - python: 3.9-dev - arch: x64 - args: > - -DPYBIND11_FINDPYTHON=ON - # These items will be removed from the build matrix, keys must match. exclude: # Currently 32bit only, and we build 64bit @@ -75,12 +75,11 @@ jobs: python: 3.8 arch: x64 - runs-on: windows-latest - python: 3.9-dev + python: 3.9 arch: x64 name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • ${{ matrix.arch }} ${{ matrix.args }}" runs-on: ${{ matrix.runs-on }} - continue-on-error: ${{ endsWith(matrix.python, 'dev') }} steps: - uses: actions/checkout@v2 @@ -196,7 +195,7 @@ jobs: - 3.9 - 5 - 7 - - 9 + - 10 - dev name: "🐍 3 • Clang ${{ matrix.clang }} • x64" diff --git a/docs/changelog.rst b/docs/changelog.rst index 3a4fb6dc4..87a769e19 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -126,6 +126,11 @@ Smaller or developer focused features: * Throw if conversion to ``str`` fails. `#2477 `_ +* 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 `_ + * Pointer to ``std::tuple`` & ``std::pair`` supported in cast. `#2334 `_ diff --git a/docs/upgrade.rst b/docs/upgrade.rst index 02d9049bb..12a7a2203 100644 --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -23,6 +23,10 @@ An error is now thrown when ``__init__`` is forgotten on subclasses. This was incorrect before, but was not checked. Add a call to ``__init__`` if it is missing. +A ``py::type_error`` is now thrown when casting to a subclass (like +``py::bytes`` from ``py::object``) if the conversion is not valid. Make a valid +conversion instead. + The undocumented ``h.get_type()`` method has been deprecated and replaced by ``py::type::of(h)``. diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 103badcc2..30d7f9aef 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -813,9 +813,9 @@ PYBIND11_NAMESPACE_END(detail) { if (!m_ptr) throw error_already_set(); } #define PYBIND11_OBJECT_CHECK_FAILED(Name, o) \ - type_error("Object of type '" + \ - pybind11::detail::get_fully_qualified_tp_name(Py_TYPE(o.ptr())) + \ - "' is not an instance of '" #Name "'") + ::pybind11::type_error("Object of type '" + \ + ::pybind11::detail::get_fully_qualified_tp_name(Py_TYPE(o.ptr())) + \ + "' is not an instance of '" #Name "'") #define PYBIND11_OBJECT(Name, Parent, CheckFun) \ PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \