Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually defining a class via attributes does not allow for passing kwargs #5406

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,21 @@ TEST_SUBMODULE(class_, m) {
});

test_class::pr4220_tripped_over_this::bind_empty0(m);

py::object parent_metaclass = py::reinterpret_borrow<py::object>((PyObject *) &PyType_Type);
py::dict attributes;

attributes["test"] = py::cpp_function(
[](py::object self [[maybe_unused]], py::object x, py::object y) {
py::print(x, y);
return 0;
},
py::arg("x"),
py::kw_only(),
py::arg("y"),
py::is_method(py::none()));

m.attr("KwOnlyMethod") = parent_metaclass("MwOnlyMethod", py::make_tuple(), attributes);
}

template <int N>
Expand Down
4 changes: 4 additions & 0 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,7 @@
m.Empty0().get_msg()
== "This is really only meant to exercise successful compilation."
)


def test_kw_only():
assert m.KwOnlyMethod().test("x", y="y") == 0

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 3.13 • ubuntu-20.04 • x64

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x7fc8dab05400>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 3.8 • ubuntu-20.04 • x64 -DPYBIND11_FINDPYTHON=ON -DCMAKE_CXX_FLAGS="-D_=1"

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x7fb7f2d3ba30>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 3.11 • ubuntu-latest • x64

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x7fe77adcf250>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 3.9 • ubuntu-20.04 • x64

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x7ff0fa1179a0>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 3.12 • ubuntu-20.04 • x64

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x7f59670c5ee0>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.10 • ubuntu-20.04 • x64

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x000000000451a870>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 graalpy-24.1 • ubuntu-20.04 • x64

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x55f5746>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.8 • ubuntu-20.04 • x64 -DPYBIND11_FINDPYTHON=ON

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x0000000004cc2b80>, 'x'; kwargs: y='y'

Check failure on line 507 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 pypy-3.9 • ubuntu-20.04 • x64

test_kw_only TypeError: (): incompatible function arguments. The following argument types are supported: 1. (x: object, *, y: object, arg1: object) -> int Invoked with: <importlib._bootstrap.MwOnlyMethod object at 0x0000000004750058>, 'x'; kwargs: y='y'
Loading