diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index c846f48a6..c70773ad0 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -185,7 +185,6 @@ public: /// Get or set the object's type_params, i.e. ``obj.__type_params__``. str_attr_accessor type_params() const; - /// Return the object's current reference count ssize_t ref_count() const { #ifdef PYPY_VERSION diff --git a/include/pybind11/typing.h b/include/pybind11/typing.h index 077eaaf46..0e6eb8485 100644 --- a/include/pybind11/typing.h +++ b/include/pybind11/typing.h @@ -124,13 +124,11 @@ class TypeVar : public object { }; #endif - - template class TypeVarObject : public object { PYBIND11_OBJECT_DEFAULT(TypeVarObject, object, PyObject_Type) using object::object; - TypeVarObject(const char *name){ + TypeVarObject(const char *name) { attr("__name__") = name; attr("__bound__") = make_caster; attr("__constraints__") = pybind11::make_tuple(); @@ -145,7 +143,7 @@ class TypeVarObject : public object { class ParamSpec : public object { PYBIND11_OBJECT_DEFAULT(ParamSpec, object, PyObject_Type) using object::object; - ParamSpec(const char *name){ + ParamSpec(const char *name) { attr("__name__") = name; attr("__bound__") = pybind11::none(); } @@ -154,9 +152,7 @@ class ParamSpec : public object { class TypeVarTuple : public object { PYBIND11_OBJECT_DEFAULT(TypeVarTuple, object, PyObject_Type) using object::object; - TypeVarTuple(const char *name){ - attr("__name__") = name; - } + TypeVarTuple(const char *name) { attr("__name__") = name; } }; PYBIND11_NAMESPACE_END(typing) diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index aa77a65b0..c1cffd0f6 100644 --- a/tests/test_pytypes.cpp +++ b/tests/test_pytypes.cpp @@ -925,14 +925,16 @@ TEST_SUBMODULE(pytypes, m) { #endif struct TypeVarObject {}; - py::class_(m, "TypeVarObject").type_params() = py::make_tuple(py::typing::TypeVarObject("T")); - + py::class_(m, "TypeVarObject").type_params() + = py::make_tuple(py::typing::TypeVarObject("T")); + struct ParamSpec {}; - py::class_(m, "ParamSpec").type_params() = py::make_tuple(py::typing::ParamSpec("P")); + py::class_(m, "ParamSpec").type_params() + = py::make_tuple(py::typing::ParamSpec("P")); struct TypeVarTuple {}; - py::class_(m, "TypeVarTuple").type_params() = py::make_tuple(py::typing::TypeVarTuple("T")); - + py::class_(m, "TypeVarTuple").type_params() + = py::make_tuple(py::typing::TypeVarTuple("T")); struct NoTypeParams {}; struct TypeParams {}; diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 6159273fe..0b31cb0d3 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -1049,6 +1049,7 @@ def test_typevar(doc): assert doc(m.annotate_object_to_T) == "annotate_object_to_T(arg0: object) -> T" + def test_typevar_object(): assert len(m.TypeVarObject.__type_params__) == 1 type_var = m.TypeVarObject.__type_params__[0] @@ -1056,6 +1057,7 @@ def test_typevar_object(): assert type_var.__bound__ == int assert type_var.__constraints__ == () + def test_param_spec(): assert len(m.ParamSpec.__type_params__) == 1 param_spec = m.ParamSpec.__type_params__[0] @@ -1063,6 +1065,7 @@ def test_param_spec(): assert param_spec.__name__ == "P" assert param_spec.__bound__ == None + def test_type_var_tuple(): assert len(m.TypeVarTuple.__type_params__) == 1 type_var_tuple = m.TypeVarTuple.__type_params__[0] @@ -1071,6 +1074,7 @@ def test_type_var_tuple(): with pytest.raises(AttributeError): param_spec.__bound__ + def test_type_params(): assert m.NoTypeParams.__type_params__ == () assert m.TypeParams.__type_params__ == ("foo", 3, None)