10000 gh-112205: Support `@setter` annotation from AC by corona10 · Pull Request #112922 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112205: Support @setter annotation from AC #112922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Dec 10, 2023
commit 0ffa78b3ce14b83a4ba7f0d528f951c8f490d35e
18 changes: 9 additions & 9 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4956,11 +4956,11 @@ Test_meth_coexist_impl(TestObj *self)
Test.property
[clinic start generated code]*/

#if defined(TEST_PROPERTY_GETSETTERDEF)
# undef TEST_PROPERTY_GETSETTERDEF
# define TEST_PROPERTY_GETSETTERDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
#if defined(TEST_PROPERTY_GETSETDEF)
# undef TEST_PROPERTY_GETSETTDEF
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
#else
# define TEST_PROPERTY_GETSETTERDEF {"property", (getter)Test_property_get, NULL, NULL},
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, NULL},
#endif

static PyObject *
Expand All @@ -4974,16 +4974,16 @@ Test_property_get(TestObj *self, void *Py_UNUSED(context))

static PyObject *
Test_property_get_impl(TestObj *self)
/*[clinic end generated code: output=606a5f21c27ff5dd input=2d92b3449fbc7d2b]*/
/*[clinic end generated code: output=c957af8739d3ae67 input=2d92b3449fbc7d2b]*/

/*[clinic input]
@setter
Test.property
[clinic start generated code]*/

#if defined(TEST_PROPERTY_GETSETTERDEF)
# undef TEST_PROPERTY_GETSETTERDEF
# define TEST_PROPERTY_GETSETTERDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
#if defined(TEST_PROPERTY_GETSETDEF)
# undef TEST_PROPERTY_GETSETDEF
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
#else
# define TEST_PROPERTY_GETSETTERDEF {"property", NULL, (setter)Test_property_set, NULL},
#endif
Expand All @@ -4999,7 +4999,7 @@ Test_property_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))

static int
Test_property_set_impl(TestObj *self, PyObject *value)
/*[clinic end generated code: output=e57ae784a4e3382a input=3bc3f46a23c83a88]*/
/*[clinic end generated code: output=1b434343ddc0380d input=3bc3f46a23c83a88]*/

/*[clinic input]
output push
Expand Down
18 changes: 9 additions & 9 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2526,9 +2526,9 @@ static PyMemberDef bufferedreader_members[] = {
};

static PyGetSetDef bufferedreader_getset[] = {
_IO__BUFFERED_CLOSED_GETSETTERDEF
_IO__BUFFERED_NAME_GETSETTERDEF
_IO__BUFFERED_MODE_GETSETTERDEF
_IO__BUFFERED_CLOSED_GETSETDEF
_IO__BUFFERED_NAME_GETSETDEF
_IO__BUFFERED_MODE_GETSETDEF
{NULL}
};

Expand Down Expand Up @@ -2586,9 +2586,9 @@ static PyMemberDef bufferedwriter_members[] = {
};

static PyGetSetDef bufferedwriter_getset[] = {
_IO__BUFFERED_CLOSED_GETSETTERDEF
_IO__BUFFERED_NAME_GETSETTERDEF
_IO__BUFFERED_MODE_GETSETTERDEF
_IO__BUFFERED_CLOSED_GETSETDEF
_IO__BUFFERED_NAME_GETSETDEF
_IO__BUFFERED_MODE_GETSETDEF
{NULL}
};

Expand Down Expand Up @@ -2704,9 +2704,9 @@ static PyMemberDef bufferedrandom_members[] = {
};

static PyGetSetDef bufferedrandom_getset[] = {
_IO__BUFFERED_CLOSED_GETSETTERDEF
_IO__BUFFERED_NAME_GETSETTERDEF
_IO__BUFFERED_MODE_GETSETTERDEF
_IO__BUFFERED_CLOSED_GETSETDEF
_IO__BUFFERED_NAME_GETSETDEF
_IO__BUFFERED_MODE_GETSETDEF
{NULL}
};

Expand Down
26 changes: 13 additions & 13 deletions Modules/_io/clinic/bufferedio.c.h

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

26 changes: 13 additions & 13 deletions Modules/_io/clinic/stringio.c.h

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

16 changes: 8 additions & 8 deletions Modules/_io/clinic/textio.c.h

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

6 changes: 3 additions & 3 deletions Modules/_io/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,15 +1037,15 @@ static struct PyMethodDef stringio_methods[] = {
};

static PyGetSetDef stringio_getset[] = {
_IO_STRINGIO_CLOSED_GETSETTERDEF
_IO_STRINGIO_NEWLINES_GETSETTERDEF
_IO_STRINGIO_CLOSED_GETSETDEF
_IO_STRINGIO_NEWLINES_GETSETDEF
/* (following comments straight off of the original Python wrapper:)
XXX Cruft to support the TextIOWrapper API. This would only
be meaningful if StringIO supported the buffer attribute.
Hopefully, a better solution, than adding these pseudo-attributes,
will be found.
*/
_IO_STRINGIO_LINE_BUFFERING_GETSETTERDEF
_IO_STRINGIO_LINE_BUFFERING_GETSETDEF
{NULL}
};

Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3355,7 +3355,7 @@ static PyGetSetDef textiowrapper_getset[] = {
*/
{"newlines", (getter)textiowrapper_newlines_get, NULL, NULL},
{"errors", (getter)textiowrapper_errors_get, NULL, NULL},
_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETTERDEF
_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
{NULL}
};

Expand Down
20 changes: 10 additions & 10 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,19 +874,19 @@ class CLanguage(Language):
{{"{name}", {methoddef_cast}{c_basename}{methoddef_cast_end}, {methoddef_flags}, {c_basename}__doc__}},
""")
GETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r"""
#if defined({getsetter_name}_GETSETTERDEF)
# undef {getsetter_name}_GETSETTERDEF
# define {getsetter_name}_GETSETTERDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, NULL}},
#if defined({getset_name}_GETSETDEF)
# undef {getset_name}_GETSETTDEF
# define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, NULL}},
#else
# define {getsetter_name}_GETSETTERDEF {{"{name}", (getter){getset_basename}_get, NULL, NULL}},
# define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, NULL, NULL}},
#endif
""")
SETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r"""
#if defined({getsetter_name}_GETSETTERDEF)
# undef {getsetter_name}_GETSETTERDEF
# define {getsetter_name}_GETSETTERDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, NULL}},
#if defined({getset_name}_GETSETDEF)
# undef {getset_name}_GETSETDEF
# define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, NULL}},
#else
# define {getsetter_name}_GETSETTERDEF {{"{name}", NULL, (setter){getset_basename}_set, NULL}},
# define {getset_name}_GETSETTERDEF {{"{name}", NULL, (setter){getset_basename}_set, NULL}},
#endif
""")
METHODDEF_PROTOTYPE_IFNDEF: Final[str] = normalize_snippet("""
Expand Down Expand Up @@ -1189,7 +1189,7 @@ def output_templates(
methoddef_define = self.GETTERDEF_PROTOTYPE_DEFINE
docstring_prototype = docstring_definition = ''
elif f.kind is SETTER:
return_value_declaration = "int return_value;"
return_value_declaration = "int {return_value};"
methoddef_define = self.SETTERDEF_PROTOTYPE_DEFINE
docstring_prototype = docstring_prototype = docstring_definition = ''
else:
Expand Down Expand Up @@ -1972,7 +1972,7 @@ def render_function(
template_dict = {'full_name': full_name}
template_dict['name'] = f.displayname
if f.kind in (GETTER, SETTER):
template_dict['getsetter_name'] = f.c_basename.upper()
template_dict['getset_name'] = f.c_basename.upper()
template_dict['getset_basename'] = f.c_basename
if f.kind is GETTER:
template_dict['c_basename'] = f.c_basename + "_get"
Expand Down
0