From 567000e63d41d51f14bbcb4a91579ad680533205 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Wed, 9 Oct 2024 15:46:43 +0800 Subject: [PATCH] feat: allow annotate methods with `pos_only` when only have the `self` argument --- include/pybind11/pybind11.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 2527d25faf..fc68b5b091 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -300,10 +300,12 @@ class cpp_function : public function { { constexpr bool has_kw_only_args = any_of...>::value, has_pos_only_args = any_of...>::value, - has_arg_annotations = any_of...>::value; + has_arg_annotations = any_of...>::value, + has_is_method = any_of...>::value; static_assert(has_arg_annotations || !has_kw_only_args, "py::kw_only requires the use of argument annotations"); - static_assert(has_arg_annotations || !has_pos_only_args, + static_assert(has_arg_annotations || !has_pos_only_args + || (has_is_method /* method has at least one argument `self` */), "py::pos_only requires the use of argument annotations (for docstrings " "and aligning the annotations to the argument)");