Skip to content

Commit

Permalink
fix: PYBIND11_OBJECT required pybind11 namespace (regression) (#2553)
Browse files Browse the repository at this point in the history
* fix: PYBIND11_OBJECT could only be used inside the pybind11 namespace (regression)

* docs: add changelog for conversion protection change

* ci: update to Python 3.9
  • Loading branch information
henryiii authored Oct 6, 2020
1 parent 9a0c96d commit 00edc30
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- 2.7
- 3.5
- 3.8
- 3.9
- pypy2
- pypy3

Expand All @@ -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-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
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.7
arch: x64

# These items will be removed from the build matrix, keys must match.
exclude:
# Currently 32bit only, and we build 64bit
Expand All @@ -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
Expand Down Expand Up @@ -196,7 +195,7 @@ jobs:
- 3.9
- 5
- 7
- 9
- 10
- dev

name: "🐍 3 • Clang ${{ matrix.clang }} • x64"
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ Smaller or developer focused features:
* Throw if conversion to ``str`` fails.
`#2477 <https://github.com/pybind/pybind11/pull/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 <https://github.com/pybind/pybind11/pull/2349>`_

* Pointer to ``std::tuple`` & ``std::pair`` supported in cast.
`#2334 <https://github.com/pybind/pybind11/pull/2334>`_

Expand Down
4 changes: 4 additions & 0 deletions docs/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)``.

Expand Down
6 changes: 3 additions & 3 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down

0 comments on commit 00edc30

Please sign in to comment.