diff options
| author | Donghee Na <donghee.na@python.org> | 2023-11-30 10:40:53 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-30 10:40:53 (GMT) |
| commit | 7eeea13403882af63a71226433c9a13b80c22564 (patch) | |
| tree | 976e1a1589211c9731fc6fec94934d415991837a /Lib/test | |
| parent | 0785c685599aaa052f85d6163872bdecb9c66486 (diff) | |
| download | cpython-7eeea13403882af63a71226433c9a13b80c22564.zip cpython-7eeea13403882af63a71226433c9a13b80c22564.tar.gz cpython-7eeea13403882af63a71226433c9a13b80c22564.tar.bz2 | |
gh-112205: Support @getter annotation from AC (gh-112396)
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/clinic.test.c | 21 | ||||
| -rw-r--r-- | Lib/test/test_clinic.py | 26 |
2 files changed, 38 insertions, 9 deletions
diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 81f88c4..ee4a422 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -4951,6 +4951,27 @@ static PyObject * Test_meth_coexist_impl(TestObj *self) /*[clinic end generated code: output=808a293d0cd27439 input=2a1d75b5e6fec6dd]*/ +/*[clinic input] +@getter +Test.property +[clinic start generated code]*/ + +#define TEST_PROPERTY_GETTERDEF \ + {"property", (getter)Test_property_get, NULL, NULL}, + +static PyObject * +Test_property_get_impl(TestObj *self); + +static PyObject * +Test_property_get(TestObj *self, void *Py_UNUSED(context)) +{ + return Test_property_get_impl(self); +} + +static PyObject * +Test_property_get_impl(TestObj *self) +/*[clinic end generated code: output=892b6fb351ff85fd input=2d92b3449fbc7d2b]*/ + /*[clinic input] output push diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index da957fc..f53e948 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -638,7 +638,7 @@ class ClinicWholeFileTest(TestCase): C.__init__ = C.meth [clinic start generated code]*/ """ - err = "'__init__' must be a normal method, not a class or static method" + err = "'__init__' must be a normal method; got 'FunctionKind.CLASS_METHOD'!" self.expect_failure(block, err, lineno=8) def test_validate_cloned_new(self): @@ -2180,14 +2180,22 @@ class ClinicParserTest(TestCase): self.expect_failure(block, err, lineno=2) def test_init_must_be_a_normal_method(self): - err = "'__init__' must be a normal method, not a class or static method!" - block = """ - module foo - class Foo "" "" - @classmethod - Foo.__init__ - """ - self.expect_failure(block, err, lineno=3) + err_template = "'__init__' must be a normal method; got 'FunctionKind.{}'!" + annotations = { + "@classmethod": "CLASS_METHOD", + "@staticmethod": "STATIC_METHOD", + "@getter": "GETTER", + } + for annotation, invalid_kind in annotations.items(): + with self.subTest(annotation=annotation, invalid_kind=invalid_kind): + block = f""" + module foo + class Foo "" "" + {annotation} + Foo.__init__ + """ + expected_error = err_template.format(invalid_kind) + self.expect_failure(block, expected_error, lineno=3) def test_duplicate_coexist(self): err = "Called @coexist twice" |
