Skip to content
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
40 changes: 39 additions & 1 deletion Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4946,6 +4946,7 @@ Test_cls_with_param_impl(TestObj *self, PyTypeObject *cls, int a)


/*[clinic input]
@vectorcall
Test.__init__
Empty init method.
[clinic start generated code]*/
Expand Down Expand Up @@ -4981,9 +4982,46 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs)
return return_value;
}

static PyObject *
Test_vectorcall(PyObject *type, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
PyObject *return_value = NULL;
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
PyObject *self;
int _result;

assert(_PyType_CAST(type)->tp_init == Test___init__);
/* Make sure the type object is immutable: the generated
* vectorcall doesn't deal e.g. with users reassigning __init__. */
assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
if (nargs) {
PyErr_SetString(PyExc_TypeError,
"Test() takes no positional arguments");
goto exit;
}
if (!_PyArg_NoKwnames("Test", kwnames)) {
goto exit;
}
self = _PyType_CAST(type)->tp_new(_PyType_CAST(type),
(PyObject *)&_Py_SINGLETON(tuple_empty), NULL);
if (self == NULL) {
goto exit;
}
_result = Test___init___impl((TestObj *)self);
if (_result != 0) {
Py_DECREF(self);
goto exit;
}
return_value = self;

exit:
return return_value;
}

static int
Test___init___impl(TestObj *self)
/*[clinic end generated code: output=f6a35c85bc5b408f input=4ea79fee54d0c3ff]*/
/*[clinic end generated code: output=3798499df7a60323 input=645fe693f6c6b9b6]*/


/*[clinic input]
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3262,8 +3262,6 @@ def test_vectorcall_on_init(self):
class Foo "FooObject *" "Foo_Type"
@vectorcall
Foo.__init__
iterable: object = NULL
/
"""
func = self.parse_function(block, signatures_in_block=3,
function_index=2)
Expand Down Expand Up @@ -3294,14 +3292,16 @@ class Foo "FooObject *" "Foo_Type"
self.expect_failure(block, err, lineno=2)

def test_vectorcall_without_type_object(self):
err = "@vectorcall requires the type object of 'Foo'"
# Heap types have no C pointer to name, so the type object is optional.
block = """
module m
class Foo "FooObject *" ""
@vectorcall
Foo.__init__
"""
self.expect_failure(block, err, lineno=3)
func = self.parse_function(block, signatures_in_block=3,
function_index=2)
self.assertTrue(func.vectorcall)

def test_vectorcall_unsupported_converter(self):
# str(encoding=...) has no parse_arg() implementation.
Expand Down
Loading
Loading