Skip to content
Merged
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
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(alias)
STRUCT_FOR_ID(allow_code)
STRUCT_FOR_ID(append)
STRUCT_FOR_ID(arg)
STRUCT_FOR_ID(argdefs)
STRUCT_FOR_ID(args)
STRUCT_FOR_ID(arguments)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 28 additions & 4 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3393,26 +3393,50 @@ def test_cloned_func_with_converter_exception_message(self):
func = getattr(ac_tester, name)
self.assertEqual(func(), name)

def test_meth_method_no_params(self):
def test_get_defining_class(self):
obj = ac_tester.TestClass()
meth = obj.meth_method_no_params
meth = obj.get_defining_class
self.assertIs(obj.get_defining_class(), ac_tester.TestClass)

# 'defining_class' argument is a positional only argument
with self.assertRaises(TypeError):
obj.get_defining_class_arg(cls=ac_tester.TestClass)

check = partial(self.assertRaisesRegex, TypeError, "no arguments")
check(meth, 1)
check(meth, a=1)

def test_meth_method_no_params_capi(self):
def test_get_defining_class_capi(self):
from _testcapi import pyobject_vectorcall
obj = ac_tester.TestClass()
meth = obj.meth_method_no_params
meth = obj.get_defining_class
pyobject_vectorcall(meth, None, None)
pyobject_vectorcall(meth, (), None)
pyobject_vectorcall(meth, (), ())
pyobject_vectorcall(meth, None, ())
self.assertIs(pyobject_vectorcall(meth, (), ()), ac_tester.TestClass)

check = partial(self.assertRaisesRegex, TypeError, "no arguments")
check(pyobject_vectorcall, meth, (1,), None)
check(pyobject_vectorcall, meth, (1,), ("a",))

def test_get_defining_class_arg(self):
obj = ac_tester.TestClass()
self.assertEqual(obj.get_defining_class_arg("arg"),
(ac_tester.TestClass, "arg"))
self.assertEqual(obj.get_defining_class_arg(arg=123),
(ac_tester.TestClass, 123))

# 'defining_class' argument is a positional only argument
with self.assertRaises(TypeError):
obj.get_defining_class_arg(cls=ac_tester.TestClass, arg="arg")

# wrong number of arguments
with self.assertRaises(TypeError):
obj.get_defining_class_arg()
with self.assertRaises(TypeError):
obj.get_defining_class_arg("arg1", "arg2")

def test_depr_star_new(self):
cls = ac_tester.DeprStarNew
cls()
Expand Down
29 changes: 22 additions & 7 deletions Modules/_testclinic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,21 +1219,36 @@ class _testclinic.TestClass "PyObject *" "PyObject"
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=668a591c65bec947]*/

/*[clinic input]
_testclinic.TestClass.meth_method_no_params
_testclinic.TestClass.get_defining_class
cls: defining_class
/
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was made on purpose.

[clinic start generated code]*/

static PyObject *
_testclinic_TestClass_meth_method_no_params_impl(PyObject *self,
PyTypeObject *cls)
/*[clinic end generated code: output=c140f100080c2fc8 input=6bd34503d11c63c1]*/
_testclinic_TestClass_get_defining_class_impl(PyObject *self,
PyTypeObject *cls)
/*[clinic end generated code: output=94f9b0b5f7add930 input=537c59417471dee3]*/
{
Py_RETURN_NONE;
return Py_NewRef(cls);
}

/*[clinic input]
_testclinic.TestClass.get_defining_class_arg
cls: defining_class
arg: object
[clinic start generated code]*/

static PyObject *
_testclinic_TestClass_get_defining_class_arg_impl(PyObject *self,
PyTypeObject *cls,
PyObject *arg)
/*[clinic end generated code: output=fe7e49d96cbb7718 input=d1b83d3b853af6d9]*/
{
return Py_BuildValue("(OO)", cls, arg);
}

static struct PyMethodDef test_class_methods[] = {
_TESTCLINIC_TESTCLASS_METH_METHOD_NO_PARAMS_METHODDEF
_TESTCLINIC_TESTCLASS_GET_DEFINING_CLASS_METHODDEF
_TESTCLINIC_TESTCLASS_GET_DEFINING_CLASS_ARG_METHODDEF
{NULL, NULL}
};

Expand Down
76 changes: 66 additions & 10 deletions Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.