summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2023-12-13 14:00:34 (GMT)
committerGitHub <noreply@github.com>2023-12-13 14:00:34 (GMT)
commit498a096a51a215cd3084845131e619222b906b3e (patch)
tree9c14ead533097de8f8fbae449de4f6cbe91c9729 /Modules/_io
parent9263173280d7ce949911965efa5b745287c581b2 (diff)
downloadcpython-498a096a51a215cd3084845131e619222b906b3e.zip
cpython-498a096a51a215cd3084845131e619222b906b3e.tar.gz
cpython-498a096a51a215cd3084845131e619222b906b3e.tar.bz2
gh-112205: Support `@setter` annotation from AC (gh-112922)
--------- Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/bufferedio.c18
-rw-r--r--Modules/_io/clinic/bufferedio.c.h26
-rw-r--r--Modules/_io/clinic/stringio.c.h26
-rw-r--r--Modules/_io/clinic/textio.c.h46
-rw-r--r--Modules/_io/stringio.c6
-rw-r--r--Modules/_io/textio.c43
6 files changed, 113 insertions, 52 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 6796268..f02207a 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -2526,9 +2526,9 @@ static PyMemberDef bufferedreader_members[] = {
};
static PyGetSetDef bufferedreader_getset[] = {
- _IO__BUFFERED_CLOSED_GETTERDEF
- _IO__BUFFERED_NAME_GETTERDEF
- _IO__BUFFERED_MODE_GETTERDEF
+ _IO__BUFFERED_CLOSED_GETSETDEF
+ _IO__BUFFERED_NAME_GETSETDEF
+ _IO__BUFFERED_MODE_GETSETDEF
{NULL}
};
@@ -2586,9 +2586,9 @@ static PyMemberDef bufferedwriter_members[] = {
};
static PyGetSetDef bufferedwriter_getset[] = {
- _IO__BUFFERED_CLOSED_GETTERDEF
- _IO__BUFFERED_NAME_GETTERDEF
- _IO__BUFFERED_MODE_GETTERDEF
+ _IO__BUFFERED_CLOSED_GETSETDEF
+ _IO__BUFFERED_NAME_GETSETDEF
+ _IO__BUFFERED_MODE_GETSETDEF
{NULL}
};
@@ -2704,9 +2704,9 @@ static PyMemberDef bufferedrandom_members[] = {
};
static PyGetSetDef bufferedrandom_getset[] = {
- _IO__BUFFERED_CLOSED_GETTERDEF
- _IO__BUFFERED_NAME_GETTERDEF
- _IO__BUFFERED_MODE_GETTERDEF
+ _IO__BUFFERED_CLOSED_GETSETDEF
+ _IO__BUFFERED_NAME_GETSETDEF
+ _IO__BUFFERED_MODE_GETSETDEF
{NULL}
};
diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h
index 69d28ad..ec46d54 100644
--- a/Modules/_io/clinic/bufferedio.c.h
+++ b/Modules/_io/clinic/bufferedio.c.h
@@ -327,8 +327,12 @@ _io__Buffered_simple_flush(buffered *self, PyObject *Py_UNUSED(ignored))
return return_value;
}
-#define _IO__BUFFERED_CLOSED_GETTERDEF \
- {"closed", (getter)_io__Buffered_closed_get, NULL, NULL},
+#if defined(_IO__BUFFERED_CLOSED_GETSETDEF)
+# undef _IO__BUFFERED_CLOSED_GETSETDEF
+# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)_io__Buffered_closed_set, NULL},
+#else
+# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, NULL, NULL},
+#endif
static PyObject *
_io__Buffered_closed_get_impl(buffered *self);
@@ -460,8 +464,12 @@ _io__Buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored))
return return_value;
}
-#define _IO__BUFFERED_NAME_GETTERDEF \
- {"name", (getter)_io__Buffered_name_get, NULL, NULL},
+#if defined(_IO__BUFFERED_NAME_GETSETDEF)
+# undef _IO__BUFFERED_NAME_GETSETDEF
+# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)_io__Buffered_name_set, NULL},
+#else
+# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, NULL, NULL},
+#endif
static PyObject *
_io__Buffered_name_get_impl(buffered *self);
@@ -478,8 +486,12 @@ _io__Buffered_name_get(buffered *self, void *Py_UNUSED(context))
return return_value;
}
-#define _IO__BUFFERED_MODE_GETTERDEF \
- {"mode", (getter)_io__Buffered_mode_get, NULL, NULL},
+#if defined(_IO__BUFFERED_MODE_GETSETDEF)
+# undef _IO__BUFFERED_MODE_GETSETDEF
+# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)_io__Buffered_mode_set, NULL},
+#else
+# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, NULL, NULL},
+#endif
static PyObject *
_io__Buffered_mode_get_impl(buffered *self);
@@ -1218,4 +1230,4 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=f21ed03255032b43 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0999c33f666dc692 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h
index ed505ae..fc2962d 100644
--- a/Modules/_io/clinic/stringio.c.h
+++ b/Modules/_io/clinic/stringio.c.h
@@ -475,8 +475,12 @@ _io_StringIO___setstate__(stringio *self, PyObject *state)
return return_value;
}
-#define _IO_STRINGIO_CLOSED_GETTERDEF \
- {"closed", (getter)_io_StringIO_closed_get, NULL, NULL},
+#if defined(_IO_STRINGIO_CLOSED_GETSETDEF)
+# undef _IO_STRINGIO_CLOSED_GETSETDEF
+# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, (setter)_io_StringIO_closed_set, NULL},
+#else
+# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, NULL, NULL},
+#endif
static PyObject *
_io_StringIO_closed_get_impl(stringio *self);
@@ -493,8 +497,12 @@ _io_StringIO_closed_get(stringio *self, void *Py_UNUSED(context))
return return_value;
}
-#define _IO_STRINGIO_LINE_BUFFERING_GETTERDEF \
- {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, NULL},
+#if defined(_IO_STRINGIO_LINE_BUFFERING_GETSETDEF)
+# undef _IO_STRINGIO_LINE_BUFFERING_GETSETDEF
+# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, (setter)_io_StringIO_line_buffering_set, NULL},
+#else
+# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, NULL},
+#endif
static PyObject *
_io_StringIO_line_buffering_get_impl(stringio *self);
@@ -511,8 +519,12 @@ _io_StringIO_line_buffering_get(stringio *self, void *Py_UNUSED(context))
return return_value;
}
-#define _IO_STRINGIO_NEWLINES_GETTERDEF \
- {"newlines", (getter)_io_StringIO_newlines_get, NULL, NULL},
+#if defined(_IO_STRINGIO_NEWLINES_GETSETDEF)
+# undef _IO_STRINGIO_NEWLINES_GETSETDEF
+# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)_io_StringIO_newlines_set, NULL},
+#else
+# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, NULL, NULL},
+#endif
static PyObject *
_io_StringIO_newlines_get_impl(stringio *self);
@@ -528,4 +540,4 @@ _io_StringIO_newlines_get(stringio *self, void *Py_UNUSED(context))
return return_value;
}
-/*[clinic end generated code: output=3a92e8b6c322f61b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=27726751d98ab617 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h
index 675e0ed..a492f34 100644
--- a/Modules/_io/clinic/textio.c.h
+++ b/Modules/_io/clinic/textio.c.h
@@ -1047,4 +1047,48 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
return return_value;
}
-/*[clinic end generated code: output=8781a91be6d99e2c input=a9049054013a1b77]*/
+
+#if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF)
+# undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
+# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL},
+#else
+# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, NULL, NULL},
+#endif
+
+static PyObject *
+_io_TextIOWrapper__CHUNK_SIZE_get_impl(textio *self);
+
+static PyObject *
+_io_TextIOWrapper__CHUNK_SIZE_get(textio *self, void *Py_UNUSED(context))
+{
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(self);
+ return_value = _io_TextIOWrapper__CHUNK_SIZE_get_impl(self);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
+}
+
+#if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF)
+# undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
+# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL},
+#else
+# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", NULL, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL},
+#endif
+
+static int
+_io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, PyObject *value);
+
+static int
+_io_TextIOWrapper__CHUNK_SIZE_set(textio *self, PyObject *value, void *Py_UNUSED(context))
+{
+ int return_value;
+
+ Py_BEGIN_CRITICAL_SECTION(self);
+ return_value = _io_TextIOWrapper__CHUNK_SIZE_set_impl(self, value);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
+}
+/*[clinic end generated code: output=b312f2d2e2221580 input=a9049054013a1b77]*/
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
index 74dcee2..06bc267 100644
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -1037,15 +1037,15 @@ static struct PyMethodDef stringio_methods[] = {
};
static PyGetSetDef stringio_getset[] = {
- _IO_STRINGIO_CLOSED_GETTERDEF
- _IO_STRINGIO_NEWLINES_GETTERDEF
+ _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_GETTERDEF
+ _IO_STRINGIO_LINE_BUFFERING_GETSETDEF
{NULL}
};
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 545f467..c76d92c 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -3238,33 +3238,37 @@ textiowrapper_errors_get(textio *self, void *context)
return result;
}
+/*[clinic input]
+@critical_section
+@getter
+_io.TextIOWrapper._CHUNK_SIZE
+[clinic start generated code]*/
+
static PyObject *
-textiowrapper_chunk_size_get_impl(textio *self, void *context)
+_io_TextIOWrapper__CHUNK_SIZE_get_impl(textio *self)
+/*[clinic end generated code: output=039925cd2df375bc input=e9715b0e06ff0fa6]*/
{
CHECK_ATTACHED(self);
return PyLong_FromSsize_t(self->chunk_size);
}
-static PyObject *
-textiowrapper_chunk_size_get(textio *self, void *context)
-{
- PyObject *result = NULL;
- Py_BEGIN_CRITICAL_SECTION(self);
- result = textiowrapper_chunk_size_get_impl(self, context);
- Py_END_CRITICAL_SECTION();
- return result;
-}
+/*[clinic input]
+@critical_section
+@setter
+_io.TextIOWrapper._CHUNK_SIZE
+[clinic start generated code]*/
static int
-textiowrapper_chunk_size_set_impl(textio *self, PyObject *arg, void *context)
+_io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, PyObject *value)
+/*[clinic end generated code: output=edb86d2db660a5ab input=32fc99861db02a0a]*/
{
Py_ssize_t n;
CHECK_ATTACHED_INT(self);
- if (arg == NULL) {
+ if (value == NULL) {
PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
return -1;
}
- n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
+ n = PyNumber_AsSsize_t(value, PyExc_ValueError);
if (n == -1 && PyErr_Occurred())
return -1;
if (n <= 0) {
@@ -3276,16 +3280,6 @@ textiowrapper_chunk_size_set_impl(textio *self, PyObject *arg, void *context)
return 0;
}
-static int
-textiowrapper_chunk_size_set(textio *self, PyObject *arg, void *context)
-{
- int result = 0;
- Py_BEGIN_CRITICAL_SECTION(self);
- result = textiowrapper_chunk_size_set_impl(self, arg, context);
- Py_END_CRITICAL_SECTION();
- return result;
-}
-
static PyMethodDef incrementalnewlinedecoder_methods[] = {
_IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF
_IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF
@@ -3361,8 +3355,7 @@ static PyGetSetDef textiowrapper_getset[] = {
*/
{"newlines", (getter)textiowrapper_newlines_get, NULL, NULL},
{"errors", (getter)textiowrapper_errors_get, NULL, NULL},
- {"_CHUNK_SIZE", (getter)textiowrapper_chunk_size_get,
- (setter)textiowrapper_chunk_size_set, NULL},
+ _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
{NULL}
};