From 9d759b63d8028a987ffad4e8750b13ecfa934967 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 11 Mar 2025 16:33:36 +0100 Subject: [PATCH 1/7] gh-111178: Change Argument Clinic signature for METH_O (#130682) Use "PyObject*" for METH_O functions to fix an undefined behavior. --- Lib/test/clinic.test.c | 4 +- Modules/_asynciomodule.c | 8 +-- Modules/_collectionsmodule.c | 4 +- Modules/_cursesmodule.c | 4 +- Modules/_elementtree.c | 22 ++++---- Modules/_hashopenssl.c | 4 +- Modules/_io/bufferedio.c | 6 +- Modules/_io/bytesio.c | 12 ++-- Modules/_io/clinic/bufferedio.c.h | 15 ++++- Modules/_io/clinic/bytesio.c.h | 28 +++++++++- Modules/_io/clinic/stringio.c.h | 6 +- Modules/_io/clinic/textio.c.h | 16 +++++- Modules/_io/textio.c | 6 +- Modules/_sqlite/clinic/connection.c.h | 16 +++++- Modules/_sqlite/clinic/cursor.c.h | 15 ++++- Modules/_sqlite/connection.c | 6 +- Modules/_sqlite/cursor.c | 4 +- Modules/_sre/clinic/sre.c.h | 28 +++++++++- Modules/_sre/sre.c | 8 +-- Modules/_struct.c | 6 +- Modules/_tkinter.c | 24 ++++---- Modules/arraymodule.c | 24 ++++---- Modules/blake2module.c | 4 +- Modules/clinic/_asynciomodule.c.h | 30 +++++++++- Modules/clinic/_collectionsmodule.c.h | 14 ++--- Modules/clinic/_cursesmodule.c.h | 15 ++++- Modules/clinic/_elementtree.c.h | 69 ++++++++++++++++++++++- Modules/clinic/_hashopenssl.c.h | 15 ++++- Modules/clinic/_randommodule.c.h | 4 +- Modules/clinic/_ssl.c.h | 6 +- Modules/clinic/_struct.c.h | 15 ++++- Modules/clinic/_tkinter.c.h | 80 ++++++++++++++++++++++++++- Modules/clinic/arraymodule.c.h | 80 ++++++++++++++++++++++++++- Modules/clinic/blake2module.c.h | 15 ++++- Modules/clinic/md5module.c.h | 15 ++++- Modules/clinic/sha1module.c.h | 15 ++++- Modules/clinic/sha2module.c.h | 28 +++++++++- Modules/clinic/sha3module.c.h | 15 ++++- Modules/md5module.c | 4 +- Modules/sha1module.c | 4 +- Modules/sha2module.c | 8 +-- Modules/sha3module.c | 4 +- Objects/bytesobject.c | 4 +- Objects/clinic/bytearrayobject.c.h | 10 ++-- Objects/clinic/bytesobject.c.h | 15 ++++- Objects/clinic/dictobject.c.h | 15 ++++- Objects/clinic/exceptions.c.h | 12 ++-- Objects/clinic/listobject.c.h | 32 ++++++++++- Objects/clinic/memoryobject.c.h | 15 ++++- Objects/clinic/setobject.c.h | 31 ++++++++--- Objects/clinic/tupleobject.c.h | 15 ++++- Objects/clinic/typeobject.c.h | 6 +- Objects/clinic/typevarobject.c.h | 41 +++++++++++++- Objects/dictobject.c | 4 +- Objects/listobject.c | 10 ++-- Objects/memoryobject.c | 4 +- Objects/setobject.c | 20 +++---- Objects/tupleobject.c | 4 +- Objects/typevarobject.c | 12 ++-- Python/bltinmodule.c | 4 +- Python/clinic/bltinmodule.c.h | 15 ++++- Python/clinic/context.c.h | 28 +++++++++- Python/context.c | 8 +-- Tools/clinic/libclinic/clanguage.py | 5 +- Tools/clinic/libclinic/converters.py | 2 + Tools/clinic/libclinic/parse_args.py | 15 +++-- 66 files changed, 843 insertions(+), 190 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 64f326903c9afd..2f843371ff9d7c 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -4940,7 +4940,7 @@ static int Test_metho_not_default_return_converter_impl(TestObj *self, PyObject *a); static PyObject * -Test_metho_not_default_return_converter(TestObj *self, PyObject *a) +Test_metho_not_default_return_converter(PyObject *self, PyObject *a) { PyObject *return_value = NULL; int _return_value; @@ -4957,7 +4957,7 @@ Test_metho_not_default_return_converter(TestObj *self, PyObject *a) static int Test_metho_not_default_return_converter_impl(TestObj *self, PyObject *a) -/*[clinic end generated code: output=b2cce75a7af2e6ce input=428657129b521177]*/ +/*[clinic end generated code: output=8b03f5213c312138 input=428657129b521177]*/ /*[clinic input] diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 99463562e67286..2038c581cf8178 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -2738,8 +2738,8 @@ _asyncio.Task.set_result [clinic start generated code]*/ static PyObject * -_asyncio_Task_set_result(TaskObj *self, PyObject *result) -/*[clinic end generated code: output=1dcae308bfcba318 input=9d1a00c07be41bab]*/ +_asyncio_Task_set_result_impl(TaskObj *self, PyObject *result) +/*[clinic end generated code: output=e9d8e3cdaf18e258 input=9d1a00c07be41bab]*/ { PyErr_SetString(PyExc_RuntimeError, "Task does not support set_result operation"); @@ -2754,8 +2754,8 @@ _asyncio.Task.set_exception [clinic start generated code]*/ static PyObject * -_asyncio_Task_set_exception(TaskObj *self, PyObject *exception) -/*[clinic end generated code: output=bc377fc28067303d input=9a8f65c83dcf893a]*/ +_asyncio_Task_set_exception_impl(TaskObj *self, PyObject *exception) +/*[clinic end generated code: output=96a91790c192cc7d input=9a8f65c83dcf893a]*/ { PyErr_SetString(PyExc_RuntimeError, "Task does not support set_exception operation"); diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index b2173d86445cc4..ad670293ec5b6a 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -484,7 +484,7 @@ deque_extend_impl(dequeobject *deque, PyObject *iterable) PyObject *s = PySequence_List(iterable); if (s == NULL) return NULL; - result = deque_extend(deque, s); + result = deque_extend((PyObject*)deque, s); Py_DECREF(s); return result; } @@ -578,7 +578,7 @@ deque_inplace_concat(PyObject *self, PyObject *other) PyObject *result; // deque_extend is thread-safe - result = deque_extend(deque, other); + result = deque_extend((PyObject*)deque, other); if (result == NULL) return result; Py_INCREF(deque); diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 5bfc6a1383f142..2c88bd3cdf2347 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -2309,8 +2309,8 @@ This information can be later retrieved using the getwin() function. [clinic start generated code]*/ static PyObject * -_curses_window_putwin(PyCursesWindowObject *self, PyObject *file) -/*[clinic end generated code: output=3a25e2a5e7a040ac input=0608648e09c8ea0a]*/ +_curses_window_putwin_impl(PyCursesWindowObject *self, PyObject *file) +/*[clinic end generated code: output=fdae68ac59b0281b input=0608648e09c8ea0a]*/ { /* We have to simulate this by writing to a temporary FILE*, then reading back, then writing to the argument file. */ diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index b5b0b82571f882..d20bbcd21fd371 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2951,8 +2951,8 @@ _elementtree.TreeBuilder.data [clinic start generated code]*/ static PyObject * -_elementtree_TreeBuilder_data(TreeBuilderObject *self, PyObject *data) -/*[clinic end generated code: output=69144c7100795bb2 input=a0540c532b284d29]*/ +_elementtree_TreeBuilder_data_impl(TreeBuilderObject *self, PyObject *data) +/*[clinic end generated code: output=dfa02b68f732b8c0 input=a0540c532b284d29]*/ { return treebuilder_handle_data(self, data); } @@ -2966,8 +2966,8 @@ _elementtree.TreeBuilder.end [clinic start generated code]*/ static PyObject * -_elementtree_TreeBuilder_end(TreeBuilderObject *self, PyObject *tag) -/*[clinic end generated code: output=9a98727cc691cd9d input=22dc3674236f5745]*/ +_elementtree_TreeBuilder_end_impl(TreeBuilderObject *self, PyObject *tag) +/*[clinic end generated code: output=84cb6ca9008ec740 input=22dc3674236f5745]*/ { return treebuilder_handle_end(self, tag); } @@ -2981,8 +2981,9 @@ _elementtree.TreeBuilder.comment [clinic start generated code]*/ static PyObject * -_elementtree_TreeBuilder_comment(TreeBuilderObject *self, PyObject *text) -/*[clinic end generated code: output=22835be41deeaa27 input=47e7ebc48ed01dfa]*/ +_elementtree_TreeBuilder_comment_impl(TreeBuilderObject *self, + PyObject *text) +/*[clinic end generated code: output=a555ef39027c3823 input=47e7ebc48ed01dfa]*/ { return treebuilder_handle_comment(self, text); } @@ -3949,8 +3950,8 @@ _elementtree.XMLParser.feed [clinic start generated code]*/ static PyObject * -_elementtree_XMLParser_feed(XMLParserObject *self, PyObject *data) -/*[clinic end generated code: output=e42b6a78eec7446d input=fe231b6b8de3ce1f]*/ +_elementtree_XMLParser_feed_impl(XMLParserObject *self, PyObject *data) +/*[clinic end generated code: output=503e6fbf1adf17ab input=fe231b6b8de3ce1f]*/ { /* feed data to parser */ @@ -3997,8 +3998,9 @@ _elementtree.XMLParser._parse_whole [clinic start generated code]*/ static PyObject * -_elementtree_XMLParser__parse_whole(XMLParserObject *self, PyObject *file) -/*[clinic end generated code: output=f797197bb818dda3 input=19ecc893b6f3e752]*/ +_elementtree_XMLParser__parse_whole_impl(XMLParserObject *self, + PyObject *file) +/*[clinic end generated code: output=60718a4e63d237d2 input=19ecc893b6f3e752]*/ { /* (internal) parse the whole input, until end of stream */ PyObject* reader; diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 4d6e4f192f5ad9..360f057ed80952 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -645,8 +645,8 @@ Update this hash object's state with the provided string. [clinic start generated code]*/ static PyObject * -EVP_update(EVPobject *self, PyObject *obj) -/*[clinic end generated code: output=ec1d55ed2432e966 input=9b30ec848f015501]*/ +EVP_update_impl(EVPobject *self, PyObject *obj) +/*[clinic end generated code: output=d56f91c68348f95f input=9b30ec848f015501]*/ { int result; Py_buffer view; diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 53c4702f673786..06a5afc52559c3 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -472,8 +472,8 @@ _io._Buffered._dealloc_warn [clinic start generated code]*/ static PyObject * -_io__Buffered__dealloc_warn(buffered *self, PyObject *source) -/*[clinic end generated code: output=690dcc3df8967162 input=8f845f2a4786391c]*/ +_io__Buffered__dealloc_warn_impl(buffered *self, PyObject *source) +/*[clinic end generated code: output=d8db21c6dec0e614 input=8f845f2a4786391c]*/ { if (self->ok && self->raw) { PyObject *r; @@ -560,7 +560,7 @@ _io__Buffered_close_impl(buffered *self) } if (self->finalizing) { - PyObject *r = _io__Buffered__dealloc_warn(self, (PyObject *) self); + PyObject *r = _io__Buffered__dealloc_warn_impl(self, (PyObject *)self); if (r) Py_DECREF(r); else diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index dc4e40b9f09a1d..e45a2d1a16dcba 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -710,8 +710,8 @@ Return the number of bytes written. [clinic start generated code]*/ static PyObject * -_io_BytesIO_write(bytesio *self, PyObject *b) -/*[clinic end generated code: output=53316d99800a0b95 input=f5ec7c8c64ed720a]*/ +_io_BytesIO_write_impl(bytesio *self, PyObject *b) +/*[clinic end generated code: output=d3e46bcec8d9e21c input=f5ec7c8c64ed720a]*/ { Py_ssize_t n = write_bytes(self, b); return n >= 0 ? PyLong_FromSsize_t(n) : NULL; @@ -730,8 +730,8 @@ each element. [clinic start generated code]*/ static PyObject * -_io_BytesIO_writelines(bytesio *self, PyObject *lines) -/*[clinic end generated code: output=7f33aa3271c91752 input=e972539176fc8fc1]*/ +_io_BytesIO_writelines_impl(bytesio *self, PyObject *lines) +/*[clinic end generated code: output=03a43a75773bc397 input=e972539176fc8fc1]*/ { PyObject *it, *item; @@ -842,7 +842,7 @@ bytesio_setstate(PyObject *op, PyObject *state) /* Set the value of the internal buffer. If state[0] does not support the buffer protocol, bytesio_write will raise the appropriate TypeError. */ - result = _io_BytesIO_write(self, PyTuple_GET_ITEM(state, 0)); + result = _io_BytesIO_write_impl(self, PyTuple_GET_ITEM(state, 0)); if (result == NULL) return NULL; Py_DECREF(result); @@ -958,7 +958,7 @@ _io_BytesIO___init___impl(bytesio *self, PyObject *initvalue) } else { PyObject *res; - res = _io_BytesIO_write(self, initvalue); + res = _io_BytesIO_write_impl(self, initvalue); if (res == NULL) return -1; Py_DECREF(res); diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 8ab8000fafee02..3345ae4c7f805f 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -307,6 +307,19 @@ PyDoc_STRVAR(_io__Buffered__dealloc_warn__doc__, #define _IO__BUFFERED__DEALLOC_WARN_METHODDEF \ {"_dealloc_warn", (PyCFunction)_io__Buffered__dealloc_warn, METH_O, _io__Buffered__dealloc_warn__doc__}, +static PyObject * +_io__Buffered__dealloc_warn_impl(buffered *self, PyObject *source); + +static PyObject * +_io__Buffered__dealloc_warn(PyObject *self, PyObject *source) +{ + PyObject *return_value = NULL; + + return_value = _io__Buffered__dealloc_warn_impl((buffered *)self, source); + + return return_value; +} + PyDoc_STRVAR(_io__Buffered_simple_flush__doc__, "flush($self, /)\n" "--\n" @@ -1246,4 +1259,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=f019d29701ba2556 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1a0562c66776fd53 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index 5528df952c33fb..dc481603d1e8a2 100644 --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -445,6 +445,19 @@ PyDoc_STRVAR(_io_BytesIO_write__doc__, #define _IO_BYTESIO_WRITE_METHODDEF \ {"write", (PyCFunction)_io_BytesIO_write, METH_O, _io_BytesIO_write__doc__}, +static PyObject * +_io_BytesIO_write_impl(bytesio *self, PyObject *b); + +static PyObject * +_io_BytesIO_write(PyObject *self, PyObject *b) +{ + PyObject *return_value = NULL; + + return_value = _io_BytesIO_write_impl((bytesio *)self, b); + + return return_value; +} + PyDoc_STRVAR(_io_BytesIO_writelines__doc__, "writelines($self, lines, /)\n" "--\n" @@ -458,6 +471,19 @@ PyDoc_STRVAR(_io_BytesIO_writelines__doc__, #define _IO_BYTESIO_WRITELINES_METHODDEF \ {"writelines", (PyCFunction)_io_BytesIO_writelines, METH_O, _io_BytesIO_writelines__doc__}, +static PyObject * +_io_BytesIO_writelines_impl(bytesio *self, PyObject *lines); + +static PyObject * +_io_BytesIO_writelines(PyObject *self, PyObject *lines) +{ + PyObject *return_value = NULL; + + return_value = _io_BytesIO_writelines_impl((bytesio *)self, lines); + + return return_value; +} + PyDoc_STRVAR(_io_BytesIO_close__doc__, "close($self, /)\n" "--\n" @@ -535,4 +561,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=8a5e153bc7584b55 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=477217b2bc464110 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index bc571698806bde..2c5757f668e93d 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -247,7 +247,7 @@ static PyObject * _io_StringIO_write_impl(stringio *self, PyObject *obj); static PyObject * -_io_StringIO_write(stringio *self, PyObject *obj) +_io_StringIO_write(PyObject *self, PyObject *obj) { PyObject *return_value = NULL; @@ -465,7 +465,7 @@ static PyObject * _io_StringIO___setstate___impl(stringio *self, PyObject *state); static PyObject * -_io_StringIO___setstate__(stringio *self, PyObject *state) +_io_StringIO___setstate__(PyObject *self, PyObject *state) { PyObject *return_value = NULL; @@ -550,4 +550,4 @@ _io_StringIO_newlines_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -/*[clinic end generated code: output=7796e223e778a214 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=69c9b100a359cbd5 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 9ce1d70ad71052..fd84198b1036de 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -457,6 +457,20 @@ PyDoc_STRVAR(_io_IncrementalNewlineDecoder_setstate__doc__, #define _IO_INCREMENTALNEWLINEDECODER_SETSTATE_METHODDEF \ {"setstate", (PyCFunction)_io_IncrementalNewlineDecoder_setstate, METH_O, _io_IncrementalNewlineDecoder_setstate__doc__}, +static PyObject * +_io_IncrementalNewlineDecoder_setstate_impl(nldecoder_object *self, + PyObject *state); + +static PyObject * +_io_IncrementalNewlineDecoder_setstate(PyObject *self, PyObject *state) +{ + PyObject *return_value = NULL; + + return_value = _io_IncrementalNewlineDecoder_setstate_impl((nldecoder_object *)self, state); + + return return_value; +} + PyDoc_STRVAR(_io_IncrementalNewlineDecoder_reset__doc__, "reset($self, /)\n" "--\n" @@ -1290,4 +1304,4 @@ _io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *value, void *Py_UNUS return return_value; } -/*[clinic end generated code: output=6e64e43113a97340 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=dad68d8c33d676e6 input=a9049054013a1b77]*/ diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 071a06ffbf7334..e07291183228b9 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -579,9 +579,9 @@ _io.IncrementalNewlineDecoder.setstate [clinic start generated code]*/ static PyObject * -_io_IncrementalNewlineDecoder_setstate(nldecoder_object *self, - PyObject *state) -/*[clinic end generated code: output=c10c622508b576cb input=c53fb505a76dbbe2]*/ +_io_IncrementalNewlineDecoder_setstate_impl(nldecoder_object *self, + PyObject *state) +/*[clinic end generated code: output=09135cb6e78a1dc8 input=c53fb505a76dbbe2]*/ { PyObject *buffer; unsigned long long flag; diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h index 82fba44eb1b074..bbdefe24a01370 100644 --- a/Modules/_sqlite/clinic/connection.c.h +++ b/Modules/_sqlite/clinic/connection.c.h @@ -1195,6 +1195,20 @@ PyDoc_STRVAR(pysqlite_connection_executescript__doc__, #define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF \ {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__}, +static PyObject * +pysqlite_connection_executescript_impl(pysqlite_Connection *self, + PyObject *script_obj); + +static PyObject * +pysqlite_connection_executescript(PyObject *self, PyObject *script_obj) +{ + PyObject *return_value = NULL; + + return_value = pysqlite_connection_executescript_impl((pysqlite_Connection *)self, script_obj); + + return return_value; +} + PyDoc_STRVAR(pysqlite_connection_interrupt__doc__, "interrupt($self, /)\n" "--\n" @@ -1881,4 +1895,4 @@ getconfig(PyObject *self, PyObject *arg) #ifndef DESERIALIZE_METHODDEF #define DESERIALIZE_METHODDEF #endif /* !defined(DESERIALIZE_METHODDEF) */ -/*[clinic end generated code: output=c59effb407b8ea4d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fc4857f09ad563b1 input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h index 590e429e9139f1..832ba2e43f02bb 100644 --- a/Modules/_sqlite/clinic/cursor.c.h +++ b/Modules/_sqlite/clinic/cursor.c.h @@ -262,6 +262,19 @@ PyDoc_STRVAR(pysqlite_cursor_setinputsizes__doc__, #define PYSQLITE_CURSOR_SETINPUTSIZES_METHODDEF \ {"setinputsizes", (PyCFunction)pysqlite_cursor_setinputsizes, METH_O, pysqlite_cursor_setinputsizes__doc__}, +static PyObject * +pysqlite_cursor_setinputsizes_impl(pysqlite_Cursor *self, PyObject *sizes); + +static PyObject * +pysqlite_cursor_setinputsizes(PyObject *self, PyObject *sizes) +{ + PyObject *return_value = NULL; + + return_value = pysqlite_cursor_setinputsizes_impl((pysqlite_Cursor *)self, sizes); + + return return_value; +} + PyDoc_STRVAR(pysqlite_cursor_setoutputsize__doc__, "setoutputsize($self, size, column=None, /)\n" "--\n" @@ -314,4 +327,4 @@ pysqlite_cursor_close(PyObject *self, PyObject *Py_UNUSED(ignored)) { return pysqlite_cursor_close_impl((pysqlite_Cursor *)self); } -/*[clinic end generated code: output=82620ca7622b547c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=02831aed7377f5f6 input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 7997e5f4d986f3..13bc0b9199c4c4 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1908,9 +1908,9 @@ Executes multiple SQL statements at once. [clinic start generated code]*/ static PyObject * -pysqlite_connection_executescript(pysqlite_Connection *self, - PyObject *script_obj) -/*[clinic end generated code: output=4c4f9d77aa0ae37d input=f6e5f1ccfa313db4]*/ +pysqlite_connection_executescript_impl(pysqlite_Connection *self, + PyObject *script_obj) +/*[clinic end generated code: output=e921c49e2291782c input=f6e5f1ccfa313db4]*/ { PyObject* result = 0; diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index ad3587d88dd854..7943bfcca3679d 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -1243,8 +1243,8 @@ Required by DB-API. Does nothing in sqlite3. [clinic start generated code]*/ static PyObject * -pysqlite_cursor_setinputsizes(pysqlite_Cursor *self, PyObject *sizes) -/*[clinic end generated code: output=893c817afe9d08ad input=de7950a3aec79bdf]*/ +pysqlite_cursor_setinputsizes_impl(pysqlite_Cursor *self, PyObject *sizes) +/*[clinic end generated code: output=a06c12790bd05f2e input=de7950a3aec79bdf]*/ { Py_RETURN_NONE; } diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h index cfc6813f37f012..1f7e037351d1c6 100644 --- a/Modules/_sre/clinic/sre.c.h +++ b/Modules/_sre/clinic/sre.c.h @@ -985,6 +985,19 @@ PyDoc_STRVAR(_sre_SRE_Pattern___deepcopy____doc__, #define _SRE_SRE_PATTERN___DEEPCOPY___METHODDEF \ {"__deepcopy__", (PyCFunction)_sre_SRE_Pattern___deepcopy__, METH_O, _sre_SRE_Pattern___deepcopy____doc__}, +static PyObject * +_sre_SRE_Pattern___deepcopy___impl(PatternObject *self, PyObject *memo); + +static PyObject * +_sre_SRE_Pattern___deepcopy__(PyObject *self, PyObject *memo) +{ + PyObject *return_value = NULL; + + return_value = _sre_SRE_Pattern___deepcopy___impl((PatternObject *)self, memo); + + return return_value; +} + #if defined(Py_DEBUG) PyDoc_STRVAR(_sre_SRE_Pattern__fail_after__doc__, @@ -1471,6 +1484,19 @@ PyDoc_STRVAR(_sre_SRE_Match___deepcopy____doc__, #define _SRE_SRE_MATCH___DEEPCOPY___METHODDEF \ {"__deepcopy__", (PyCFunction)_sre_SRE_Match___deepcopy__, METH_O, _sre_SRE_Match___deepcopy____doc__}, +static PyObject * +_sre_SRE_Match___deepcopy___impl(MatchObject *self, PyObject *memo); + +static PyObject * +_sre_SRE_Match___deepcopy__(PyObject *self, PyObject *memo) +{ + PyObject *return_value = NULL; + + return_value = _sre_SRE_Match___deepcopy___impl((MatchObject *)self, memo); + + return return_value; +} + PyDoc_STRVAR(_sre_SRE_Scanner_match__doc__, "match($self, /)\n" "--\n" @@ -1516,4 +1542,4 @@ _sre_SRE_Scanner_search(PyObject *self, PyTypeObject *cls, PyObject *const *args #ifndef _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF #define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF #endif /* !defined(_SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF) */ -/*[clinic end generated code: output=3654103c87eb4830 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=45baae8bdfafdc51 input=a9049054013a1b77]*/ diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c index 54f0e64d4819f1..1c0e44c933a7bf 100644 --- a/Modules/_sre/sre.c +++ b/Modules/_sre/sre.c @@ -1482,8 +1482,8 @@ _sre.SRE_Pattern.__deepcopy__ [clinic start generated code]*/ static PyObject * -_sre_SRE_Pattern___deepcopy__(PatternObject *self, PyObject *memo) -/*[clinic end generated code: output=2ad25679c1f1204a input=a465b1602f997bed]*/ +_sre_SRE_Pattern___deepcopy___impl(PatternObject *self, PyObject *memo) +/*[clinic end generated code: output=75efe69bd12c5d7d input=a465b1602f997bed]*/ { return Py_NewRef(self); } @@ -2659,8 +2659,8 @@ _sre.SRE_Match.__deepcopy__ [clinic start generated code]*/ static PyObject * -_sre_SRE_Match___deepcopy__(MatchObject *self, PyObject *memo) -/*[clinic end generated code: output=ba7cb46d655e4ee2 input=779d12a31c2c325e]*/ +_sre_SRE_Match___deepcopy___impl(MatchObject *self, PyObject *memo) +/*[clinic end generated code: output=2b657578eb03f4a3 input=779d12a31c2c325e]*/ { return Py_NewRef(self); } diff --git a/Modules/_struct.c b/Modules/_struct.c index f096998cb714e7..f04805d9d6d1d7 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -2131,8 +2131,8 @@ Requires that the bytes length be a multiple of the struct size. [clinic start generated code]*/ static PyObject * -Struct_iter_unpack(PyStructObject *self, PyObject *buffer) -/*[clinic end generated code: output=172d83d0cd15dbab input=6d65b3f3107dbc99]*/ +Struct_iter_unpack_impl(PyStructObject *self, PyObject *buffer) +/*[clinic end generated code: output=818f89ad4afa8d64 input=6d65b3f3107dbc99]*/ { _structmodulestate *state = get_struct_state_structinst(self); unpackiterobject *iter; @@ -2691,7 +2691,7 @@ iter_unpack_impl(PyObject *module, PyStructObject *s_object, PyObject *buffer) /*[clinic end generated code: output=0ae50e250d20e74d input=b214a58869a3c98d]*/ { - return Struct_iter_unpack(s_object, buffer); + return Struct_iter_unpack((PyObject*)s_object, buffer); } static struct PyMethodDef module_functions[] = { diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 3351a778c42cf5..c7cc3a8071dc1c 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -2010,8 +2010,8 @@ _tkinter.tkapp.getint [clinic start generated code]*/ static PyObject * -_tkinter_tkapp_getint(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=88cf293fae307cfe input=034026997c5b91f8]*/ +_tkinter_tkapp_getint_impl(TkappObject *self, PyObject *arg) +/*[clinic end generated code: output=5f75d31b260d4086 input=034026997c5b91f8]*/ { char *s; Tcl_Obj *value; @@ -2055,8 +2055,8 @@ _tkinter.tkapp.getdouble [clinic start generated code]*/ static PyObject * -_tkinter_tkapp_getdouble(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=c52b138bd8b956b9 input=22015729ce9ef7f8]*/ +_tkinter_tkapp_getdouble_impl(TkappObject *self, PyObject *arg) +/*[clinic end generated code: output=432433f2f52b09b6 input=22015729ce9ef7f8]*/ { char *s; double v; @@ -2094,8 +2094,8 @@ _tkinter.tkapp.getboolean [clinic start generated code]*/ static PyObject * -_tkinter_tkapp_getboolean(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=726a9ae445821d91 input=7f11248ef8f8776e]*/ +_tkinter_tkapp_getboolean_impl(TkappObject *self, PyObject *arg) +/*[clinic end generated code: output=3b05597cf2bfbd9f input=7f11248ef8f8776e]*/ { char *s; int v; @@ -2258,8 +2258,8 @@ _tkinter.tkapp.splitlist [clinic start generated code]*/ static PyObject * -_tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) -/*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ +_tkinter_tkapp_splitlist_impl(TkappObject *self, PyObject *arg) +/*[clinic end generated code: output=e517f462159c3000 input=2b2e13351e3c0b53]*/ { char *list; Tcl_Size argc, i; @@ -2676,8 +2676,8 @@ _tkinter.tkapp.deletefilehandler [clinic start generated code]*/ static PyObject * -_tkinter_tkapp_deletefilehandler(TkappObject *self, PyObject *file) -/*[clinic end generated code: output=b53cc96ebf9476fd input=abbec19d66312e2a]*/ +_tkinter_tkapp_deletefilehandler_impl(TkappObject *self, PyObject *file) +/*[clinic end generated code: output=30b2c6ed195b0410 input=abbec19d66312e2a]*/ { int tfile; @@ -3010,8 +3010,8 @@ Set the tracing function. [clinic start generated code]*/ static PyObject * -_tkinter_tkapp_settrace(TkappObject *self, PyObject *func) -/*[clinic end generated code: output=847f6ebdf46e84fa input=31b260d46d3d018a]*/ +_tkinter_tkapp_settrace_impl(TkappObject *self, PyObject *func) +/*[clinic end generated code: output=8c59938bc9005607 input=31b260d46d3d018a]*/ { if (func == Py_None) { func = NULL; diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 5b86ec98393e48..16f757feca3342 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -929,8 +929,8 @@ Return a copy of the array. [clinic start generated code]*/ static PyObject * -array_array___deepcopy__(arrayobject *self, PyObject *unused) -/*[clinic end generated code: output=1ec748d8e14a9faa input=2405ecb4933748c4]*/ +array_array___deepcopy___impl(arrayobject *self, PyObject *unused) +/*[clinic end generated code: output=703b4c412feaaf31 input=2405ecb4933748c4]*/ { return array_array___copy___impl(self); } @@ -1174,8 +1174,8 @@ Return number of occurrences of v in the array. [clinic start generated code]*/ static PyObject * -array_array_count(arrayobject *self, PyObject *v) -/*[clinic end generated code: output=3dd3624bf7135a3a input=d9bce9d65e39d1f5]*/ +array_array_count_impl(arrayobject *self, PyObject *v) +/*[clinic end generated code: output=93ead26a2affb739 input=d9bce9d65e39d1f5]*/ { Py_ssize_t count = 0; Py_ssize_t i; @@ -1272,8 +1272,8 @@ Remove the first occurrence of v in the array. [clinic start generated code]*/ static PyObject * -array_array_remove(arrayobject *self, PyObject *v) -/*[clinic end generated code: output=bef06be9fdf9dceb input=0b1e5aed25590027]*/ +array_array_remove_impl(arrayobject *self, PyObject *v) +/*[clinic end generated code: output=f2a24e288ecb2a35 input=0b1e5aed25590027]*/ { Py_ssize_t i; @@ -1420,8 +1420,8 @@ Append new value v to the end of the array. [clinic start generated code]*/ static PyObject * -array_array_append(arrayobject *self, PyObject *v) -/*[clinic end generated code: output=745a0669bf8db0e2 input=0b98d9d78e78f0fa]*/ +array_array_append_impl(arrayobject *self, PyObject *v) +/*[clinic end generated code: output=2f1e8cbad70c2a8b input=0b98d9d78e78f0fa]*/ { return ins(self, Py_SIZE(self), v); } @@ -1642,8 +1642,8 @@ Append items to array from list. [clinic start generated code]*/ static PyObject * -array_array_fromlist(arrayobject *self, PyObject *list) -/*[clinic end generated code: output=26411c2d228a3e3f input=be2605a96c49680f]*/ +array_array_fromlist_impl(arrayobject *self, PyObject *list) +/*[clinic end generated code: output=6c23733a68dd68df input=be2605a96c49680f]*/ { Py_ssize_t n; @@ -3102,8 +3102,8 @@ Set state information for unpickling. [clinic start generated code]*/ static PyObject * -array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state) -/*[clinic end generated code: output=397da9904e443cbe input=f47d5ceda19e787b]*/ +array_arrayiterator___setstate___impl(arrayiterobject *self, PyObject *state) +/*[clinic end generated code: output=d7837ae4ac1fd8b9 input=f47d5ceda19e787b]*/ { Py_ssize_t index = PyLong_AsSsize_t(state); if (index == -1 && PyErr_Occurred()) diff --git a/Modules/blake2module.c b/Modules/blake2module.c index 016c834c01bbe2..f55d93a3066025 100644 --- a/Modules/blake2module.c +++ b/Modules/blake2module.c @@ -739,8 +739,8 @@ Update this hash object's state with the provided bytes-like object. [clinic start generated code]*/ static PyObject * -_blake2_blake2b_update(Blake2Object *self, PyObject *data) -/*[clinic end generated code: output=e6d1ac88471df308 input=ffc4aa6a6a225d31]*/ +_blake2_blake2b_update_impl(Blake2Object *self, PyObject *data) +/*[clinic end generated code: output=99330230068e8c99 input=ffc4aa6a6a225d31]*/ { Py_buffer buf; diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodule.c.h index d25411ee9958a1..d529b09bd1529f 100644 --- a/Modules/clinic/_asynciomodule.c.h +++ b/Modules/clinic/_asynciomodule.c.h @@ -1403,6 +1403,19 @@ PyDoc_STRVAR(_asyncio_Task_set_result__doc__, #define _ASYNCIO_TASK_SET_RESULT_METHODDEF \ {"set_result", (PyCFunction)_asyncio_Task_set_result, METH_O, _asyncio_Task_set_result__doc__}, +static PyObject * +_asyncio_Task_set_result_impl(TaskObj *self, PyObject *result); + +static PyObject * +_asyncio_Task_set_result(PyObject *self, PyObject *result) +{ + PyObject *return_value = NULL; + + return_value = _asyncio_Task_set_result_impl((TaskObj *)self, result); + + return return_value; +} + PyDoc_STRVAR(_asyncio_Task_set_exception__doc__, "set_exception($self, exception, /)\n" "--\n" @@ -1411,6 +1424,19 @@ PyDoc_STRVAR(_asyncio_Task_set_exception__doc__, #define _ASYNCIO_TASK_SET_EXCEPTION_METHODDEF \ {"set_exception", (PyCFunction)_asyncio_Task_set_exception, METH_O, _asyncio_Task_set_exception__doc__}, +static PyObject * +_asyncio_Task_set_exception_impl(TaskObj *self, PyObject *exception); + +static PyObject * +_asyncio_Task_set_exception(PyObject *self, PyObject *exception) +{ + PyObject *return_value = NULL; + + return_value = _asyncio_Task_set_exception_impl((TaskObj *)self, exception); + + return return_value; +} + PyDoc_STRVAR(_asyncio_Task_get_coro__doc__, "get_coro($self, /)\n" "--\n" @@ -1486,7 +1512,7 @@ static PyObject * _asyncio_Task_set_name_impl(TaskObj *self, PyObject *value); static PyObject * -_asyncio_Task_set_name(TaskObj *self, PyObject *value) +_asyncio_Task_set_name(PyObject *self, PyObject *value) { PyObject *return_value = NULL; @@ -2174,4 +2200,4 @@ _asyncio_future_discard_from_awaited_by(PyObject *module, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=f14ff14c29c691ec input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b1060b180d9dd54c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index ddf18c2c77a8cd..c7dc639ce87ad8 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -71,7 +71,7 @@ static PyObject * deque_append_impl(dequeobject *deque, PyObject *item); static PyObject * -deque_append(dequeobject *deque, PyObject *item) +deque_append(PyObject *deque, PyObject *item) { PyObject *return_value = NULL; @@ -95,7 +95,7 @@ static PyObject * deque_appendleft_impl(dequeobject *deque, PyObject *item); static PyObject * -deque_appendleft(dequeobject *deque, PyObject *item) +deque_appendleft(PyObject *deque, PyObject *item) { PyObject *return_value = NULL; @@ -119,7 +119,7 @@ static PyObject * deque_extend_impl(dequeobject *deque, PyObject *iterable); static PyObject * -deque_extend(dequeobject *deque, PyObject *iterable) +deque_extend(PyObject *deque, PyObject *iterable) { PyObject *return_value = NULL; @@ -143,7 +143,7 @@ static PyObject * deque_extendleft_impl(dequeobject *deque, PyObject *iterable); static PyObject * -deque_extendleft(dequeobject *deque, PyObject *iterable) +deque_extendleft(PyObject *deque, PyObject *iterable) { PyObject *return_value = NULL; @@ -308,7 +308,7 @@ static PyObject * deque_count_impl(dequeobject *deque, PyObject *v); static PyObject * -deque_count(dequeobject *deque, PyObject *v) +deque_count(PyObject *deque, PyObject *v) { PyObject *return_value = NULL; @@ -423,7 +423,7 @@ static PyObject * deque_remove_impl(dequeobject *deque, PyObject *value); static PyObject * -deque_remove(dequeobject *deque, PyObject *value) +deque_remove(PyObject *deque, PyObject *value) { PyObject *return_value = NULL; @@ -630,4 +630,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=2d89c39288fc7389 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1eb3634d5ef8b407 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h index 8291d5d635c79d..769d75c09010bd 100644 --- a/Modules/clinic/_cursesmodule.c.h +++ b/Modules/clinic/_cursesmodule.c.h @@ -1479,6 +1479,19 @@ PyDoc_STRVAR(_curses_window_putwin__doc__, #define _CURSES_WINDOW_PUTWIN_METHODDEF \ {"putwin", (PyCFunction)_curses_window_putwin, METH_O, _curses_window_putwin__doc__}, +static PyObject * +_curses_window_putwin_impl(PyCursesWindowObject *self, PyObject *file); + +static PyObject * +_curses_window_putwin(PyObject *self, PyObject *file) +{ + PyObject *return_value = NULL; + + return_value = _curses_window_putwin_impl((PyCursesWindowObject *)self, file); + + return return_value; +} + PyDoc_STRVAR(_curses_window_redrawln__doc__, "redrawln($self, beg, num, /)\n" "--\n" @@ -4379,4 +4392,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored #ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF #define _CURSES_USE_DEFAULT_COLORS_METHODDEF #endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */ -/*[clinic end generated code: output=c4211865ed96c2af input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ce2d19df9e20bfa3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index 78391887b615cf..e79f20d86204bb 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -984,6 +984,19 @@ PyDoc_STRVAR(_elementtree_TreeBuilder_data__doc__, #define _ELEMENTTREE_TREEBUILDER_DATA_METHODDEF \ {"data", (PyCFunction)_elementtree_TreeBuilder_data, METH_O, _elementtree_TreeBuilder_data__doc__}, +static PyObject * +_elementtree_TreeBuilder_data_impl(TreeBuilderObject *self, PyObject *data); + +static PyObject * +_elementtree_TreeBuilder_data(PyObject *self, PyObject *data) +{ + PyObject *return_value = NULL; + + return_value = _elementtree_TreeBuilder_data_impl((TreeBuilderObject *)self, data); + + return return_value; +} + PyDoc_STRVAR(_elementtree_TreeBuilder_end__doc__, "end($self, tag, /)\n" "--\n" @@ -992,6 +1005,19 @@ PyDoc_STRVAR(_elementtree_TreeBuilder_end__doc__, #define _ELEMENTTREE_TREEBUILDER_END_METHODDEF \ {"end", (PyCFunction)_elementtree_TreeBuilder_end, METH_O, _elementtree_TreeBuilder_end__doc__}, +static PyObject * +_elementtree_TreeBuilder_end_impl(TreeBuilderObject *self, PyObject *tag); + +static PyObject * +_elementtree_TreeBuilder_end(PyObject *self, PyObject *tag) +{ + PyObject *return_value = NULL; + + return_value = _elementtree_TreeBuilder_end_impl((TreeBuilderObject *)self, tag); + + return return_value; +} + PyDoc_STRVAR(_elementtree_TreeBuilder_comment__doc__, "comment($self, text, /)\n" "--\n" @@ -1000,6 +1026,20 @@ PyDoc_STRVAR(_elementtree_TreeBuilder_comment__doc__, #define _ELEMENTTREE_TREEBUILDER_COMMENT_METHODDEF \ {"comment", (PyCFunction)_elementtree_TreeBuilder_comment, METH_O, _elementtree_TreeBuilder_comment__doc__}, +static PyObject * +_elementtree_TreeBuilder_comment_impl(TreeBuilderObject *self, + PyObject *text); + +static PyObject * +_elementtree_TreeBuilder_comment(PyObject *self, PyObject *text) +{ + PyObject *return_value = NULL; + + return_value = _elementtree_TreeBuilder_comment_impl((TreeBuilderObject *)self, text); + + return return_value; +} + PyDoc_STRVAR(_elementtree_TreeBuilder_pi__doc__, "pi($self, target, text=None, /)\n" "--\n" @@ -1206,6 +1246,19 @@ PyDoc_STRVAR(_elementtree_XMLParser_feed__doc__, #define _ELEMENTTREE_XMLPARSER_FEED_METHODDEF \ {"feed", (PyCFunction)_elementtree_XMLParser_feed, METH_O, _elementtree_XMLParser_feed__doc__}, +static PyObject * +_elementtree_XMLParser_feed_impl(XMLParserObject *self, PyObject *data); + +static PyObject * +_elementtree_XMLParser_feed(PyObject *self, PyObject *data) +{ + PyObject *return_value = NULL; + + return_value = _elementtree_XMLParser_feed_impl((XMLParserObject *)self, data); + + return return_value; +} + PyDoc_STRVAR(_elementtree_XMLParser__parse_whole__doc__, "_parse_whole($self, file, /)\n" "--\n" @@ -1214,6 +1267,20 @@ PyDoc_STRVAR(_elementtree_XMLParser__parse_whole__doc__, #define _ELEMENTTREE_XMLPARSER__PARSE_WHOLE_METHODDEF \ {"_parse_whole", (PyCFunction)_elementtree_XMLParser__parse_whole, METH_O, _elementtree_XMLParser__parse_whole__doc__}, +static PyObject * +_elementtree_XMLParser__parse_whole_impl(XMLParserObject *self, + PyObject *file); + +static PyObject * +_elementtree_XMLParser__parse_whole(PyObject *self, PyObject *file) +{ + PyObject *return_value = NULL; + + return_value = _elementtree_XMLParser__parse_whole_impl((XMLParserObject *)self, file); + + return return_value; +} + PyDoc_STRVAR(_elementtree_XMLParser__setevents__doc__, "_setevents($self, events_queue, events_to_report=None, /)\n" "--\n" @@ -1248,4 +1315,4 @@ _elementtree_XMLParser__setevents(PyObject *self, PyObject *const *args, Py_ssiz exit: return return_value; } -/*[clinic end generated code: output=e5c758958f14f102 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0eed58350c3c1832 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index d219b80b791a66..7bf6af1eeeba24 100644 --- a/Modules/clinic/_hashopenssl.c.h +++ b/Modules/clinic/_hashopenssl.c.h @@ -72,6 +72,19 @@ PyDoc_STRVAR(EVP_update__doc__, #define EVP_UPDATE_METHODDEF \ {"update", (PyCFunction)EVP_update, METH_O, EVP_update__doc__}, +static PyObject * +EVP_update_impl(EVPobject *self, PyObject *obj); + +static PyObject * +EVP_update(PyObject *self, PyObject *obj) +{ + PyObject *return_value = NULL; + + return_value = EVP_update_impl((EVPobject *)self, obj); + + return return_value; +} + #if defined(PY_OPENSSL_HAS_SHAKE) PyDoc_STRVAR(EVPXOF_digest__doc__, @@ -1844,4 +1857,4 @@ _hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t narg #ifndef _HASHLIB_SCRYPT_METHODDEF #define _HASHLIB_SCRYPT_METHODDEF #endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */ -/*[clinic end generated code: output=811a8b50beae1018 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e9624853a73bb65a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_randommodule.c.h b/Modules/clinic/_randommodule.c.h index b2d67e11c63595..1e989e970c9de5 100644 --- a/Modules/clinic/_randommodule.c.h +++ b/Modules/clinic/_randommodule.c.h @@ -103,7 +103,7 @@ static PyObject * _random_Random_setstate_impl(RandomObject *self, PyObject *state); static PyObject * -_random_Random_setstate(RandomObject *self, PyObject *state) +_random_Random_setstate(PyObject *self, PyObject *state) { PyObject *return_value = NULL; @@ -143,4 +143,4 @@ _random_Random_getrandbits(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=859cfbf59c133a4e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4458b5a69201ebea input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 73c5d304f1a141..9656f09c471931 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -1520,7 +1520,7 @@ static PyObject * _ssl__SSLContext_load_dh_params_impl(PySSLContext *self, PyObject *filepath); static PyObject * -_ssl__SSLContext_load_dh_params(PySSLContext *self, PyObject *filepath) +_ssl__SSLContext_load_dh_params(PyObject *self, PyObject *filepath) { PyObject *return_value = NULL; @@ -1784,7 +1784,7 @@ static PyObject * _ssl__SSLContext_set_ecdh_curve_impl(PySSLContext *self, PyObject *name); static PyObject * -_ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name) +_ssl__SSLContext_set_ecdh_curve(PyObject *self, PyObject *name) { PyObject *return_value = NULL; @@ -2878,4 +2878,4 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje #ifndef _SSL_ENUM_CRLS_METHODDEF #define _SSL_ENUM_CRLS_METHODDEF #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */ -/*[clinic end generated code: output=bededfb2b927bd41 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c402c53dc30a14fa input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h index 7cf179f7a69d55..0e50395f70d827 100644 --- a/Modules/clinic/_struct.c.h +++ b/Modules/clinic/_struct.c.h @@ -209,6 +209,19 @@ PyDoc_STRVAR(Struct_iter_unpack__doc__, #define STRUCT_ITER_UNPACK_METHODDEF \ {"iter_unpack", (PyCFunction)Struct_iter_unpack, METH_O, Struct_iter_unpack__doc__}, +static PyObject * +Struct_iter_unpack_impl(PyStructObject *self, PyObject *buffer); + +static PyObject * +Struct_iter_unpack(PyObject *self, PyObject *buffer) +{ + PyObject *return_value = NULL; + + return_value = Struct_iter_unpack_impl((PyStructObject *)self, buffer); + + return return_value; +} + PyDoc_STRVAR(_clearcache__doc__, "_clearcache($module, /)\n" "--\n" @@ -439,4 +452,4 @@ iter_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -/*[clinic end generated code: output=ec540c21be08e1d0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c7c051850b7ad427 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_tkinter.c.h b/Modules/clinic/_tkinter.c.h index d6e783b04fe968..352c2b9e3d410c 100644 --- a/Modules/clinic/_tkinter.c.h +++ b/Modules/clinic/_tkinter.c.h @@ -156,6 +156,19 @@ PyDoc_STRVAR(_tkinter_tkapp_getint__doc__, #define _TKINTER_TKAPP_GETINT_METHODDEF \ {"getint", (PyCFunction)_tkinter_tkapp_getint, METH_O, _tkinter_tkapp_getint__doc__}, +static PyObject * +_tkinter_tkapp_getint_impl(TkappObject *self, PyObject *arg); + +static PyObject * +_tkinter_tkapp_getint(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + + return_value = _tkinter_tkapp_getint_impl((TkappObject *)self, arg); + + return return_value; +} + PyDoc_STRVAR(_tkinter_tkapp_getdouble__doc__, "getdouble($self, arg, /)\n" "--\n" @@ -164,6 +177,19 @@ PyDoc_STRVAR(_tkinter_tkapp_getdouble__doc__, #define _TKINTER_TKAPP_GETDOUBLE_METHODDEF \ {"getdouble", (PyCFunction)_tkinter_tkapp_getdouble, METH_O, _tkinter_tkapp_getdouble__doc__}, +static PyObject * +_tkinter_tkapp_getdouble_impl(TkappObject *self, PyObject *arg); + +static PyObject * +_tkinter_tkapp_getdouble(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + + return_value = _tkinter_tkapp_getdouble_impl((TkappObject *)self, arg); + + return return_value; +} + PyDoc_STRVAR(_tkinter_tkapp_getboolean__doc__, "getboolean($self, arg, /)\n" "--\n" @@ -172,6 +198,19 @@ PyDoc_STRVAR(_tkinter_tkapp_getboolean__doc__, #define _TKINTER_TKAPP_GETBOOLEAN_METHODDEF \ {"getboolean", (PyCFunction)_tkinter_tkapp_getboolean, METH_O, _tkinter_tkapp_getboolean__doc__}, +static PyObject * +_tkinter_tkapp_getboolean_impl(TkappObject *self, PyObject *arg); + +static PyObject * +_tkinter_tkapp_getboolean(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + + return_value = _tkinter_tkapp_getboolean_impl((TkappObject *)self, arg); + + return return_value; +} + PyDoc_STRVAR(_tkinter_tkapp_exprstring__doc__, "exprstring($self, s, /)\n" "--\n" @@ -324,6 +363,19 @@ PyDoc_STRVAR(_tkinter_tkapp_splitlist__doc__, #define _TKINTER_TKAPP_SPLITLIST_METHODDEF \ {"splitlist", (PyCFunction)_tkinter_tkapp_splitlist, METH_O, _tkinter_tkapp_splitlist__doc__}, +static PyObject * +_tkinter_tkapp_splitlist_impl(TkappObject *self, PyObject *arg); + +static PyObject * +_tkinter_tkapp_splitlist(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + + return_value = _tkinter_tkapp_splitlist_impl((TkappObject *)self, arg); + + return return_value; +} + PyDoc_STRVAR(_tkinter_tkapp_createcommand__doc__, "createcommand($self, name, func, /)\n" "--\n" @@ -451,6 +503,19 @@ PyDoc_STRVAR(_tkinter_tkapp_deletefilehandler__doc__, #define _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF \ {"deletefilehandler", (PyCFunction)_tkinter_tkapp_deletefilehandler, METH_O, _tkinter_tkapp_deletefilehandler__doc__}, +static PyObject * +_tkinter_tkapp_deletefilehandler_impl(TkappObject *self, PyObject *file); + +static PyObject * +_tkinter_tkapp_deletefilehandler(PyObject *self, PyObject *file) +{ + PyObject *return_value = NULL; + + return_value = _tkinter_tkapp_deletefilehandler_impl((TkappObject *)self, file); + + return return_value; +} + #endif /* defined(HAVE_CREATEFILEHANDLER) */ PyDoc_STRVAR(_tkinter_tktimertoken_deletetimerhandler__doc__, @@ -631,6 +696,19 @@ PyDoc_STRVAR(_tkinter_tkapp_settrace__doc__, #define _TKINTER_TKAPP_SETTRACE_METHODDEF \ {"settrace", (PyCFunction)_tkinter_tkapp_settrace, METH_O, _tkinter_tkapp_settrace__doc__}, +static PyObject * +_tkinter_tkapp_settrace_impl(TkappObject *self, PyObject *func); + +static PyObject * +_tkinter_tkapp_settrace(PyObject *self, PyObject *func) +{ + PyObject *return_value = NULL; + + return_value = _tkinter_tkapp_settrace_impl((TkappObject *)self, func); + + return return_value; +} + PyDoc_STRVAR(_tkinter_tkapp_gettrace__doc__, "gettrace($self, /)\n" "--\n" @@ -888,4 +966,4 @@ _tkinter_getbusywaitinterval(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #define _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #endif /* !defined(_TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF) */ -/*[clinic end generated code: output=172a98df5f209a84 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=052c067aa69237be input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index c5b62b16699d06..97e5ca771f3a90 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -53,6 +53,19 @@ PyDoc_STRVAR(array_array___deepcopy____doc__, #define ARRAY_ARRAY___DEEPCOPY___METHODDEF \ {"__deepcopy__", (PyCFunction)array_array___deepcopy__, METH_O, array_array___deepcopy____doc__}, +static PyObject * +array_array___deepcopy___impl(arrayobject *self, PyObject *unused); + +static PyObject * +array_array___deepcopy__(PyObject *self, PyObject *unused) +{ + PyObject *return_value = NULL; + + return_value = array_array___deepcopy___impl((arrayobject *)self, unused); + + return return_value; +} + PyDoc_STRVAR(array_array_count__doc__, "count($self, v, /)\n" "--\n" @@ -62,6 +75,19 @@ PyDoc_STRVAR(array_array_count__doc__, #define ARRAY_ARRAY_COUNT_METHODDEF \ {"count", (PyCFunction)array_array_count, METH_O, array_array_count__doc__}, +static PyObject * +array_array_count_impl(arrayobject *self, PyObject *v); + +static PyObject * +array_array_count(PyObject *self, PyObject *v) +{ + PyObject *return_value = NULL; + + return_value = array_array_count_impl((arrayobject *)self, v); + + return return_value; +} + PyDoc_STRVAR(array_array_index__doc__, "index($self, v, start=0, stop=sys.maxsize, /)\n" "--\n" @@ -117,6 +143,19 @@ PyDoc_STRVAR(array_array_remove__doc__, #define ARRAY_ARRAY_REMOVE_METHODDEF \ {"remove", (PyCFunction)array_array_remove, METH_O, array_array_remove__doc__}, +static PyObject * +array_array_remove_impl(arrayobject *self, PyObject *v); + +static PyObject * +array_array_remove(PyObject *self, PyObject *v) +{ + PyObject *return_value = NULL; + + return_value = array_array_remove_impl((arrayobject *)self, v); + + return return_value; +} + PyDoc_STRVAR(array_array_pop__doc__, "pop($self, i=-1, /)\n" "--\n" @@ -277,6 +316,19 @@ PyDoc_STRVAR(array_array_append__doc__, #define ARRAY_ARRAY_APPEND_METHODDEF \ {"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__}, +static PyObject * +array_array_append_impl(arrayobject *self, PyObject *v); + +static PyObject * +array_array_append(PyObject *self, PyObject *v) +{ + PyObject *return_value = NULL; + + return_value = array_array_append_impl((arrayobject *)self, v); + + return return_value; +} + PyDoc_STRVAR(array_array_byteswap__doc__, "byteswap($self, /)\n" "--\n" @@ -427,6 +479,19 @@ PyDoc_STRVAR(array_array_fromlist__doc__, #define ARRAY_ARRAY_FROMLIST_METHODDEF \ {"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__}, +static PyObject * +array_array_fromlist_impl(arrayobject *self, PyObject *list); + +static PyObject * +array_array_fromlist(PyObject *self, PyObject *list) +{ + PyObject *return_value = NULL; + + return_value = array_array_fromlist_impl((arrayobject *)self, list); + + return return_value; +} + PyDoc_STRVAR(array_array_tolist__doc__, "tolist($self, /)\n" "--\n" @@ -695,4 +760,17 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__, #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=8120dc5c4fa414b9 input=a9049054013a1b77]*/ + +static PyObject * +array_arrayiterator___setstate___impl(arrayiterobject *self, PyObject *state); + +static PyObject * +array_arrayiterator___setstate__(PyObject *self, PyObject *state) +{ + PyObject *return_value = NULL; + + return_value = array_arrayiterator___setstate___impl((arrayiterobject *)self, state); + + return return_value; +} +/*[clinic end generated code: output=dd49451ac1cc3f39 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/blake2module.c.h b/Modules/clinic/blake2module.c.h index b5ac90143a1740..9450334bd676ef 100644 --- a/Modules/clinic/blake2module.c.h +++ b/Modules/clinic/blake2module.c.h @@ -426,6 +426,19 @@ PyDoc_STRVAR(_blake2_blake2b_update__doc__, #define _BLAKE2_BLAKE2B_UPDATE_METHODDEF \ {"update", (PyCFunction)_blake2_blake2b_update, METH_O, _blake2_blake2b_update__doc__}, +static PyObject * +_blake2_blake2b_update_impl(Blake2Object *self, PyObject *data); + +static PyObject * +_blake2_blake2b_update(PyObject *self, PyObject *data) +{ + PyObject *return_value = NULL; + + return_value = _blake2_blake2b_update_impl((Blake2Object *)self, data); + + return return_value; +} + PyDoc_STRVAR(_blake2_blake2b_digest__doc__, "digest($self, /)\n" "--\n" @@ -461,4 +474,4 @@ _blake2_blake2b_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _blake2_blake2b_hexdigest_impl((Blake2Object *)self); } -/*[clinic end generated code: output=6e03c947b7e0d973 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b286a0d1be8729b0 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/md5module.c.h b/Modules/clinic/md5module.c.h index 1f0acebf47b6ff..fc42bfb61f59e1 100644 --- a/Modules/clinic/md5module.c.h +++ b/Modules/clinic/md5module.c.h @@ -75,6 +75,19 @@ PyDoc_STRVAR(MD5Type_update__doc__, #define MD5TYPE_UPDATE_METHODDEF \ {"update", (PyCFunction)MD5Type_update, METH_O, MD5Type_update__doc__}, +static PyObject * +MD5Type_update_impl(MD5object *self, PyObject *obj); + +static PyObject * +MD5Type_update(PyObject *self, PyObject *obj) +{ + PyObject *return_value = NULL; + + return_value = MD5Type_update_impl((MD5object *)self, obj); + + return return_value; +} + PyDoc_STRVAR(_md5_md5__doc__, "md5($module, /, string=b\'\', *, usedforsecurity=True)\n" "--\n" @@ -149,4 +162,4 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw exit: return return_value; } -/*[clinic end generated code: output=a4292eab710dcb60 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=10db0ff2ecf97159 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha1module.c.h b/Modules/clinic/sha1module.c.h index ddd8e66a41d7ff..792059d9b89bb2 100644 --- a/Modules/clinic/sha1module.c.h +++ b/Modules/clinic/sha1module.c.h @@ -75,6 +75,19 @@ PyDoc_STRVAR(SHA1Type_update__doc__, #define SHA1TYPE_UPDATE_METHODDEF \ {"update", (PyCFunction)SHA1Type_update, METH_O, SHA1Type_update__doc__}, +static PyObject * +SHA1Type_update_impl(SHA1object *self, PyObject *obj); + +static PyObject * +SHA1Type_update(PyObject *self, PyObject *obj) +{ + PyObject *return_value = NULL; + + return_value = SHA1Type_update_impl((SHA1object *)self, obj); + + return return_value; +} + PyDoc_STRVAR(_sha1_sha1__doc__, "sha1($module, /, string=b\'\', *, usedforsecurity=True)\n" "--\n" @@ -149,4 +162,4 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * exit: return return_value; } -/*[clinic end generated code: output=ad6f3788a6e7ff6f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3cfa7b6a9f99b5b2 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha2module.c.h b/Modules/clinic/sha2module.c.h index d86f5510d752e8..5e4b97b8ed3c1d 100644 --- a/Modules/clinic/sha2module.c.h +++ b/Modules/clinic/sha2module.c.h @@ -133,6 +133,19 @@ PyDoc_STRVAR(SHA256Type_update__doc__, #define SHA256TYPE_UPDATE_METHODDEF \ {"update", (PyCFunction)SHA256Type_update, METH_O, SHA256Type_update__doc__}, +static PyObject * +SHA256Type_update_impl(SHA256object *self, PyObject *obj); + +static PyObject * +SHA256Type_update(PyObject *self, PyObject *obj) +{ + PyObject *return_value = NULL; + + return_value = SHA256Type_update_impl((SHA256object *)self, obj); + + return return_value; +} + PyDoc_STRVAR(SHA512Type_update__doc__, "update($self, obj, /)\n" "--\n" @@ -142,6 +155,19 @@ PyDoc_STRVAR(SHA512Type_update__doc__, #define SHA512TYPE_UPDATE_METHODDEF \ {"update", (PyCFunction)SHA512Type_update, METH_O, SHA512Type_update__doc__}, +static PyObject * +SHA512Type_update_impl(SHA512object *self, PyObject *obj); + +static PyObject * +SHA512Type_update(PyObject *self, PyObject *obj) +{ + PyObject *return_value = NULL; + + return_value = SHA512Type_update_impl((SHA512object *)self, obj); + + return return_value; +} + PyDoc_STRVAR(_sha2_sha256__doc__, "sha256($module, /, string=b\'\', *, usedforsecurity=True)\n" "--\n" @@ -441,4 +467,4 @@ _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject exit: return return_value; } -/*[clinic end generated code: output=1d7fec114eb6b6e3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0c2eed5c77ec6987 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha3module.c.h b/Modules/clinic/sha3module.c.h index 729e216ce023cf..98d8f10a96ee48 100644 --- a/Modules/clinic/sha3module.c.h +++ b/Modules/clinic/sha3module.c.h @@ -142,6 +142,19 @@ PyDoc_STRVAR(_sha3_sha3_224_update__doc__, #define _SHA3_SHA3_224_UPDATE_METHODDEF \ {"update", (PyCFunction)_sha3_sha3_224_update, METH_O, _sha3_sha3_224_update__doc__}, +static PyObject * +_sha3_sha3_224_update_impl(SHA3object *self, PyObject *data); + +static PyObject * +_sha3_sha3_224_update(PyObject *self, PyObject *data) +{ + PyObject *return_value = NULL; + + return_value = _sha3_sha3_224_update_impl((SHA3object *)self, data); + + return return_value; +} + PyDoc_STRVAR(_sha3_shake_128_digest__doc__, "digest($self, length, /)\n" "--\n" @@ -195,4 +208,4 @@ _sha3_shake_128_hexdigest(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=21da06d9570969d8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=437023d9eac08551 input=a9049054013a1b77]*/ diff --git a/Modules/md5module.c b/Modules/md5module.c index d86c8e555012d7..b4f279c3fbadfd 100644 --- a/Modules/md5module.c +++ b/Modules/md5module.c @@ -194,8 +194,8 @@ Update this hash object's state with the provided string. [clinic start generated code]*/ static PyObject * -MD5Type_update(MD5object *self, PyObject *obj) -/*[clinic end generated code: output=f6ad168416338423 input=6e1efcd9ecf17032]*/ +MD5Type_update_impl(MD5object *self, PyObject *obj) +/*[clinic end generated code: output=b0fed9a7ce7ad253 input=6e1efcd9ecf17032]*/ { Py_buffer buf; diff --git a/Modules/sha1module.c b/Modules/sha1module.c index d0b1e8250770d0..2ff00b3ae58e4f 100644 --- a/Modules/sha1module.c +++ b/Modules/sha1module.c @@ -187,8 +187,8 @@ Update this hash object's state with the provided string. [clinic start generated code]*/ static PyObject * -SHA1Type_update(SHA1object *self, PyObject *obj) -/*[clinic end generated code: output=d9902f0e5015e9ae input=aad8e07812edbba3]*/ +SHA1Type_update_impl(SHA1object *self, PyObject *obj) +/*[clinic end generated code: output=cdc8e0e106dbec5f input=aad8e07812edbba3]*/ { Py_buffer buf; diff --git a/Modules/sha2module.c b/Modules/sha2module.c index 45fa120cf76758..be79cbc0b1c477 100644 --- a/Modules/sha2module.c +++ b/Modules/sha2module.c @@ -368,8 +368,8 @@ Update this hash object's state with the provided string. [clinic start generated code]*/ static PyObject * -SHA256Type_update(SHA256object *self, PyObject *obj) -/*[clinic end generated code: output=1b240f965ddbd8c6 input=b2d449d5b30f0f5a]*/ +SHA256Type_update_impl(SHA256object *self, PyObject *obj) +/*[clinic end generated code: output=dc58a580cf8905a5 input=b2d449d5b30f0f5a]*/ { Py_buffer buf; @@ -402,8 +402,8 @@ Update this hash object's state with the provided string. [clinic start generated code]*/ static PyObject * -SHA512Type_update(SHA512object *self, PyObject *obj) -/*[clinic end generated code: output=745f51057a985884 input=ded2b46656566283]*/ +SHA512Type_update_impl(SHA512object *self, PyObject *obj) +/*[clinic end generated code: output=9af211766c0b7365 input=ded2b46656566283]*/ { Py_buffer buf; diff --git a/Modules/sha3module.c b/Modules/sha3module.c index 72a11602b0e1fd..5514033d997aec 100644 --- a/Modules/sha3module.c +++ b/Modules/sha3module.c @@ -271,8 +271,8 @@ Update this hash object's state with the provided bytes-like object. [clinic start generated code]*/ static PyObject * -_sha3_sha3_224_update(SHA3object *self, PyObject *data) -/*[clinic end generated code: output=d3223352286ed357 input=a887f54dcc4ae227]*/ +_sha3_sha3_224_update_impl(SHA3object *self, PyObject *data) +/*[clinic end generated code: output=390b7abf7c9795a5 input=a887f54dcc4ae227]*/ { Py_buffer buf; diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index b3d1c425ad18b7..ba642d3788fc78 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -1883,8 +1883,8 @@ Example: b'.'.join([b'ab', b'pq', b'rs']) -> b'ab.pq.rs'. [clinic start generated code]*/ static PyObject * -bytes_join(PyBytesObject *self, PyObject *iterable_of_bytes) -/*[clinic end generated code: output=a046f379f626f6f8 input=7fe377b95bd549d2]*/ +bytes_join_impl(PyBytesObject *self, PyObject *iterable_of_bytes) +/*[clinic end generated code: output=0687abb94d7d438e input=7fe377b95bd549d2]*/ { return stringlib_bytes_join((PyObject*)self, iterable_of_bytes); } diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 183ad13dd3448e..fa105f74c58512 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -929,7 +929,7 @@ static PyObject * bytearray_partition_impl(PyByteArrayObject *self, PyObject *sep); static PyObject * -bytearray_partition(PyByteArrayObject *self, PyObject *sep) +bytearray_partition(PyObject *self, PyObject *sep) { PyObject *return_value = NULL; @@ -961,7 +961,7 @@ static PyObject * bytearray_rpartition_impl(PyByteArrayObject *self, PyObject *sep); static PyObject * -bytearray_rpartition(PyByteArrayObject *self, PyObject *sep) +bytearray_rpartition(PyObject *self, PyObject *sep) { PyObject *return_value = NULL; @@ -1186,7 +1186,7 @@ static PyObject * bytearray_extend_impl(PyByteArrayObject *self, PyObject *iterable_of_ints); static PyObject * -bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints) +bytearray_extend(PyObject *self, PyObject *iterable_of_ints) { PyObject *return_value = NULL; @@ -1509,7 +1509,7 @@ static PyObject * bytearray_join_impl(PyByteArrayObject *self, PyObject *iterable_of_bytes); static PyObject * -bytearray_join(PyByteArrayObject *self, PyObject *iterable_of_bytes) +bytearray_join(PyObject *self, PyObject *iterable_of_bytes) { PyObject *return_value = NULL; @@ -1789,4 +1789,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=5e33422343b47af9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7c924a56e0a8bfe6 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index 9aef736428ad0e..11cb81a9c5c9d7 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -296,6 +296,19 @@ PyDoc_STRVAR(bytes_join__doc__, #define BYTES_JOIN_METHODDEF \ {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__}, +static PyObject * +bytes_join_impl(PyBytesObject *self, PyObject *iterable_of_bytes); + +static PyObject * +bytes_join(PyObject *self, PyObject *iterable_of_bytes) +{ + PyObject *return_value = NULL; + + return_value = bytes_join_impl((PyBytesObject *)self, iterable_of_bytes); + + return return_value; +} + PyDoc_STRVAR(bytes_find__doc__, "find($self, sub[, start[, end]], /)\n" "--\n" @@ -1391,4 +1404,4 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=96fe2d6ef9ac8f6a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=61cb2cf6506df4c6 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index c66916bb33aa37..36da98f7477d59 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -66,6 +66,19 @@ PyDoc_STRVAR(dict___contains____doc__, #define DICT___CONTAINS___METHODDEF \ {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__}, +static PyObject * +dict___contains___impl(PyDictObject *self, PyObject *key); + +static PyObject * +dict___contains__(PyObject *self, PyObject *key) +{ + PyObject *return_value = NULL; + + return_value = dict___contains___impl((PyDictObject *)self, key); + + return return_value; +} + PyDoc_STRVAR(dict_get__doc__, "get($self, key, default=None, /)\n" "--\n" @@ -310,4 +323,4 @@ dict_values(PyObject *self, PyObject *Py_UNUSED(ignored)) { return dict_values_impl((PyDictObject *)self); } -/*[clinic end generated code: output=0f04bf0e7e6b130f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8a104741e4676c76 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/exceptions.c.h b/Objects/clinic/exceptions.c.h index 8699df07495ad8..9baac8b1cc660b 100644 --- a/Objects/clinic/exceptions.c.h +++ b/Objects/clinic/exceptions.c.h @@ -40,7 +40,7 @@ static PyObject * BaseException___setstate___impl(PyBaseExceptionObject *self, PyObject *state); static PyObject * -BaseException___setstate__(PyBaseExceptionObject *self, PyObject *state) +BaseException___setstate__(PyObject *self, PyObject *state) { PyObject *return_value = NULL; @@ -64,7 +64,7 @@ static PyObject * BaseException_with_traceback_impl(PyBaseExceptionObject *self, PyObject *tb); static PyObject * -BaseException_with_traceback(PyBaseExceptionObject *self, PyObject *tb) +BaseException_with_traceback(PyObject *self, PyObject *tb) { PyObject *return_value = NULL; @@ -322,7 +322,7 @@ BaseExceptionGroup_derive_impl(PyBaseExceptionGroupObject *self, PyObject *excs); static PyObject * -BaseExceptionGroup_derive(PyBaseExceptionGroupObject *self, PyObject *excs) +BaseExceptionGroup_derive(PyObject *self, PyObject *excs) { PyObject *return_value = NULL; @@ -346,7 +346,7 @@ BaseExceptionGroup_split_impl(PyBaseExceptionGroupObject *self, PyObject *matcher_value); static PyObject * -BaseExceptionGroup_split(PyBaseExceptionGroupObject *self, PyObject *matcher_value) +BaseExceptionGroup_split(PyObject *self, PyObject *matcher_value) { PyObject *return_value = NULL; @@ -370,7 +370,7 @@ BaseExceptionGroup_subgroup_impl(PyBaseExceptionGroupObject *self, PyObject *matcher_value); static PyObject * -BaseExceptionGroup_subgroup(PyBaseExceptionGroupObject *self, PyObject *matcher_value) +BaseExceptionGroup_subgroup(PyObject *self, PyObject *matcher_value) { PyObject *return_value = NULL; @@ -380,4 +380,4 @@ BaseExceptionGroup_subgroup(PyBaseExceptionGroupObject *self, PyObject *matcher_ return return_value; } -/*[clinic end generated code: output=19aed708dcaf7184 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fcf70b3b71f3d14a input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index a29ed9f7088700..3f4e7e72f85dc2 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -114,7 +114,7 @@ static PyObject * list_append_impl(PyListObject *self, PyObject *object); static PyObject * -list_append(PyListObject *self, PyObject *object) +list_append(PyObject *self, PyObject *object) { PyObject *return_value = NULL; @@ -134,6 +134,19 @@ PyDoc_STRVAR(list_extend__doc__, #define LIST_EXTEND_METHODDEF \ {"extend", (PyCFunction)list_extend, METH_O, list_extend__doc__}, +static PyObject * +list_extend_impl(PyListObject *self, PyObject *iterable); + +static PyObject * +list_extend(PyObject *self, PyObject *iterable) +{ + PyObject *return_value = NULL; + + return_value = list_extend_impl((PyListObject *)self, iterable); + + return return_value; +} + PyDoc_STRVAR(list_pop__doc__, "pop($self, index=-1, /)\n" "--\n" @@ -341,6 +354,19 @@ PyDoc_STRVAR(list_count__doc__, #define LIST_COUNT_METHODDEF \ {"count", (PyCFunction)list_count, METH_O, list_count__doc__}, +static PyObject * +list_count_impl(PyListObject *self, PyObject *value); + +static PyObject * +list_count(PyObject *self, PyObject *value) +{ + PyObject *return_value = NULL; + + return_value = list_count_impl((PyListObject *)self, value); + + return return_value; +} + PyDoc_STRVAR(list_remove__doc__, "remove($self, value, /)\n" "--\n" @@ -356,7 +382,7 @@ static PyObject * list_remove_impl(PyListObject *self, PyObject *value); static PyObject * -list_remove(PyListObject *self, PyObject *value) +list_remove(PyObject *self, PyObject *value) { PyObject *return_value = NULL; @@ -440,4 +466,4 @@ list___reversed__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl((PyListObject *)self); } -/*[clinic end generated code: output=35c43dc33f9ba521 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bc45e43a621ac833 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index 4706c92051926c..3d9a94665d6fc8 100644 --- a/Objects/clinic/memoryobject.c.h +++ b/Objects/clinic/memoryobject.c.h @@ -428,6 +428,19 @@ PyDoc_STRVAR(memoryview_count__doc__, #define MEMORYVIEW_COUNT_METHODDEF \ {"count", (PyCFunction)memoryview_count, METH_O, memoryview_count__doc__}, +static PyObject * +memoryview_count_impl(PyMemoryViewObject *self, PyObject *value); + +static PyObject * +memoryview_count(PyObject *self, PyObject *value) +{ + PyObject *return_value = NULL; + + return_value = memoryview_count_impl((PyMemoryViewObject *)self, value); + + return return_value; +} + PyDoc_STRVAR(memoryview_index__doc__, "index($self, value, start=0, stop=sys.maxsize, /)\n" "--\n" @@ -473,4 +486,4 @@ memoryview_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=2ef6c061d9c4e3dc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c0371164b68a6839 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/setobject.c.h b/Objects/clinic/setobject.c.h index bf7e604e4b0a46..96c70d0ae95a46 100644 --- a/Objects/clinic/setobject.c.h +++ b/Objects/clinic/setobject.c.h @@ -223,7 +223,7 @@ static PyObject * set_isdisjoint_impl(PySetObject *so, PyObject *other); static PyObject * -set_isdisjoint(PySetObject *so, PyObject *other) +set_isdisjoint(PyObject *so, PyObject *other) { PyObject *return_value = NULL; @@ -297,6 +297,19 @@ PyDoc_STRVAR(set_symmetric_difference_update__doc__, #define SET_SYMMETRIC_DIFFERENCE_UPDATE_METHODDEF \ {"symmetric_difference_update", (PyCFunction)set_symmetric_difference_update, METH_O, set_symmetric_difference_update__doc__}, +static PyObject * +set_symmetric_difference_update_impl(PySetObject *so, PyObject *other); + +static PyObject * +set_symmetric_difference_update(PyObject *so, PyObject *other) +{ + PyObject *return_value = NULL; + + return_value = set_symmetric_difference_update_impl((PySetObject *)so, other); + + return return_value; +} + PyDoc_STRVAR(set_symmetric_difference__doc__, "symmetric_difference($self, other, /)\n" "--\n" @@ -310,7 +323,7 @@ static PyObject * set_symmetric_difference_impl(PySetObject *so, PyObject *other); static PyObject * -set_symmetric_difference(PySetObject *so, PyObject *other) +set_symmetric_difference(PyObject *so, PyObject *other) { PyObject *return_value = NULL; @@ -334,7 +347,7 @@ static PyObject * set_issubset_impl(PySetObject *so, PyObject *other); static PyObject * -set_issubset(PySetObject *so, PyObject *other) +set_issubset(PyObject *so, PyObject *other) { PyObject *return_value = NULL; @@ -358,7 +371,7 @@ static PyObject * set_issuperset_impl(PySetObject *so, PyObject *other); static PyObject * -set_issuperset(PySetObject *so, PyObject *other) +set_issuperset(PyObject *so, PyObject *other) { PyObject *return_value = NULL; @@ -384,7 +397,7 @@ static PyObject * set_add_impl(PySetObject *so, PyObject *key); static PyObject * -set_add(PySetObject *so, PyObject *key) +set_add(PyObject *so, PyObject *key) { PyObject *return_value = NULL; @@ -408,7 +421,7 @@ static PyObject * set___contains___impl(PySetObject *so, PyObject *key); static PyObject * -set___contains__(PySetObject *so, PyObject *key) +set___contains__(PyObject *so, PyObject *key) { PyObject *return_value = NULL; @@ -434,7 +447,7 @@ static PyObject * set_remove_impl(PySetObject *so, PyObject *key); static PyObject * -set_remove(PySetObject *so, PyObject *key) +set_remove(PyObject *so, PyObject *key) { PyObject *return_value = NULL; @@ -461,7 +474,7 @@ static PyObject * set_discard_impl(PySetObject *so, PyObject *key); static PyObject * -set_discard(PySetObject *so, PyObject *key) +set_discard(PyObject *so, PyObject *key) { PyObject *return_value = NULL; @@ -519,4 +532,4 @@ set___sizeof__(PyObject *so, PyObject *Py_UNUSED(ignored)) return return_value; } -/*[clinic end generated code: output=83b7742a762ce465 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e2f1470de062d661 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/tupleobject.c.h b/Objects/clinic/tupleobject.c.h index 40ffd4c1755769..1c12706c0bb43b 100644 --- a/Objects/clinic/tupleobject.c.h +++ b/Objects/clinic/tupleobject.c.h @@ -59,6 +59,19 @@ PyDoc_STRVAR(tuple_count__doc__, #define TUPLE_COUNT_METHODDEF \ {"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__}, +static PyObject * +tuple_count_impl(PyTupleObject *self, PyObject *value); + +static PyObject * +tuple_count(PyObject *self, PyObject *value) +{ + PyObject *return_value = NULL; + + return_value = tuple_count_impl((PyTupleObject *)self, value); + + return return_value; +} + PyDoc_STRVAR(tuple_new__doc__, "tuple(iterable=(), /)\n" "--\n" @@ -114,4 +127,4 @@ tuple___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return tuple___getnewargs___impl((PyTupleObject *)self); } -/*[clinic end generated code: output=779cb4a13db67397 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bd11662d62d973c2 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/typeobject.c.h b/Objects/clinic/typeobject.c.h index 5e8187b3f5b748..24a25f27ea3cc3 100644 --- a/Objects/clinic/typeobject.c.h +++ b/Objects/clinic/typeobject.c.h @@ -17,7 +17,7 @@ static int type___instancecheck___impl(PyTypeObject *self, PyObject *instance); static PyObject * -type___instancecheck__(PyTypeObject *self, PyObject *instance) +type___instancecheck__(PyObject *self, PyObject *instance) { PyObject *return_value = NULL; int _return_value; @@ -45,7 +45,7 @@ static int type___subclasscheck___impl(PyTypeObject *self, PyObject *subclass); static PyObject * -type___subclasscheck__(PyTypeObject *self, PyObject *subclass) +type___subclasscheck__(PyObject *self, PyObject *subclass) { PyObject *return_value = NULL; int _return_value; @@ -262,4 +262,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return object___dir___impl(self); } -/*[clinic end generated code: output=f7db85fd11818c63 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b55c0d257e2518d2 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/typevarobject.c.h b/Objects/clinic/typevarobject.c.h index e50ed7d95b9b2a..87e0fd77203f75 100644 --- a/Objects/clinic/typevarobject.c.h +++ b/Objects/clinic/typevarobject.c.h @@ -130,6 +130,19 @@ PyDoc_STRVAR(typevar_typing_subst__doc__, #define TYPEVAR_TYPING_SUBST_METHODDEF \ {"__typing_subst__", (PyCFunction)typevar_typing_subst, METH_O, typevar_typing_subst__doc__}, +static PyObject * +typevar_typing_subst_impl(typevarobject *self, PyObject *arg); + +static PyObject * +typevar_typing_subst(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + + return_value = typevar_typing_subst_impl((typevarobject *)self, arg); + + return return_value; +} + PyDoc_STRVAR(typevar_typing_prepare_subst__doc__, "__typing_prepare_subst__($self, alias, args, /)\n" "--\n" @@ -418,6 +431,19 @@ PyDoc_STRVAR(paramspec_typing_subst__doc__, #define PARAMSPEC_TYPING_SUBST_METHODDEF \ {"__typing_subst__", (PyCFunction)paramspec_typing_subst, METH_O, paramspec_typing_subst__doc__}, +static PyObject * +paramspec_typing_subst_impl(paramspecobject *self, PyObject *arg); + +static PyObject * +paramspec_typing_subst(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + + return_value = paramspec_typing_subst_impl((paramspecobject *)self, arg); + + return return_value; +} + PyDoc_STRVAR(paramspec_typing_prepare_subst__doc__, "__typing_prepare_subst__($self, alias, args, /)\n" "--\n" @@ -557,6 +583,19 @@ PyDoc_STRVAR(typevartuple_typing_subst__doc__, #define TYPEVARTUPLE_TYPING_SUBST_METHODDEF \ {"__typing_subst__", (PyCFunction)typevartuple_typing_subst, METH_O, typevartuple_typing_subst__doc__}, +static PyObject * +typevartuple_typing_subst_impl(typevartupleobject *self, PyObject *arg); + +static PyObject * +typevartuple_typing_subst(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + + return_value = typevartuple_typing_subst_impl((typevartupleobject *)self, arg); + + return return_value; +} + PyDoc_STRVAR(typevartuple_typing_prepare_subst__doc__, "__typing_prepare_subst__($self, alias, args, /)\n" "--\n" @@ -706,4 +745,4 @@ typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=f499d959a942c599 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d0cdf708e2e315a4 input=a9049054013a1b77]*/ diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 8a30c4082e9236..d74bec775e43f2 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -4234,8 +4234,8 @@ True if the dictionary has the specified key, else False. [clinic start generated code]*/ static PyObject * -dict___contains__(PyDictObject *self, PyObject *key) -/*[clinic end generated code: output=a3d03db709ed6e6b input=fe1cb42ad831e820]*/ +dict___contains___impl(PyDictObject *self, PyObject *key) +/*[clinic end generated code: output=1b314e6da7687dae input=fe1cb42ad831e820]*/ { int contains = PyDict_Contains((PyObject *)self, key); if (contains < 0) { diff --git a/Objects/listobject.c b/Objects/listobject.c index 2893acf6d6e143..4ad2b032f64c62 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1416,8 +1416,8 @@ Extend list by appending elements from the iterable. [clinic start generated code]*/ static PyObject * -list_extend(PyListObject *self, PyObject *iterable) -/*[clinic end generated code: output=630fb3bca0c8e789 input=979da7597a515791]*/ +list_extend_impl(PyListObject *self, PyObject *iterable) +/*[clinic end generated code: output=b0eba9e0b186d5ce input=979da7597a515791]*/ { if (_list_extend(self, iterable) < 0) { return NULL; @@ -1428,7 +1428,7 @@ list_extend(PyListObject *self, PyObject *iterable) PyObject * _PyList_Extend(PyListObject *self, PyObject *iterable) { - return list_extend(self, iterable); + return list_extend((PyObject*)self, iterable); } int @@ -3272,8 +3272,8 @@ Return number of occurrences of value. [clinic start generated code]*/ static PyObject * -list_count(PyListObject *self, PyObject *value) -/*[clinic end generated code: output=b1f5d284205ae714 input=3bdc3a5e6f749565]*/ +list_count_impl(PyListObject *self, PyObject *value) +/*[clinic end generated code: output=eff66f14aef2df86 input=3bdc3a5e6f749565]*/ { Py_ssize_t count = 0; for (Py_ssize_t i = 0; ; i++) { diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 331363b2babbef..cf673fb379edcd 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -2781,8 +2781,8 @@ Count the number of occurrences of a value. [clinic start generated code]*/ static PyObject * -memoryview_count(PyMemoryViewObject *self, PyObject *value) -/*[clinic end generated code: output=e2c255a8d54eaa12 input=e3036ce1ed7d1823]*/ +memoryview_count_impl(PyMemoryViewObject *self, PyObject *value) +/*[clinic end generated code: output=a15cb19311985063 input=e3036ce1ed7d1823]*/ { PyObject *iter = PyObject_GetIter(_PyObject_CAST(self)); if (iter == NULL) { diff --git a/Objects/setobject.c b/Objects/setobject.c index 1978ae2b165d18..27b370e8e4fb05 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1933,8 +1933,8 @@ Update the set, keeping only elements found in either set, but not in both. [clinic start generated code]*/ static PyObject * -set_symmetric_difference_update(PySetObject *so, PyObject *other) -/*[clinic end generated code: output=fbb049c0806028de input=a50acf0365e1f0a5]*/ +set_symmetric_difference_update_impl(PySetObject *so, PyObject *other) +/*[clinic end generated code: output=79f80b4ee5da66c1 input=a50acf0365e1f0a5]*/ { if (Py_Is((PyObject *)so, other)) { return set_clear((PyObject *)so, NULL); @@ -2004,7 +2004,7 @@ set_xor(PyObject *self, PyObject *other) if (!PyAnySet_Check(self) || !PyAnySet_Check(other)) Py_RETURN_NOTIMPLEMENTED; PySetObject *so = _PySet_CAST(self); - return set_symmetric_difference(so, other); + return set_symmetric_difference((PyObject*)so, other); } static PyObject * @@ -2016,7 +2016,7 @@ set_ixor(PyObject *self, PyObject *other) Py_RETURN_NOTIMPLEMENTED; PySetObject *so = _PySet_CAST(self); - result = set_symmetric_difference_update(so, other); + result = set_symmetric_difference_update((PyObject*)so, other); if (result == NULL) return NULL; Py_DECREF(result); @@ -2083,7 +2083,7 @@ set_issuperset_impl(PySetObject *so, PyObject *other) /*[clinic end generated code: output=ecf00ce552c09461 input=5f2e1f262e6e4ccc]*/ { if (PyAnySet_Check(other)) { - return set_issubset((PySetObject *)other, (PyObject *)so); + return set_issubset(other, (PyObject *)so); } PyObject *key, *it = PyObject_GetIter(other); @@ -2127,7 +2127,7 @@ set_richcompare(PyObject *self, PyObject *w, int op) ((PySetObject *)w)->hash != -1 && v->hash != ((PySetObject *)w)->hash) Py_RETURN_FALSE; - return set_issubset(v, w); + return set_issubset((PyObject*)v, w); case Py_NE: r1 = set_richcompare((PyObject*)v, w, Py_EQ); if (r1 == NULL) @@ -2138,17 +2138,17 @@ set_richcompare(PyObject *self, PyObject *w, int op) return NULL; return PyBool_FromLong(!r2); case Py_LE: - return set_issubset(v, w); + return set_issubset((PyObject*)v, w); case Py_GE: - return set_issuperset(v, w); + return set_issuperset((PyObject*)v, w); case Py_LT: if (PySet_GET_SIZE(v) >= PySet_GET_SIZE(w)) Py_RETURN_FALSE; - return set_issubset(v, w); + return set_issubset((PyObject*)v, w); case Py_GT: if (PySet_GET_SIZE(v) <= PySet_GET_SIZE(w)) Py_RETURN_FALSE; - return set_issuperset(v, w); + return set_issuperset((PyObject*)v, w); } Py_RETURN_NOTIMPLEMENTED; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index b7416a5a1c5372..1b2b53646da6d9 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -604,8 +604,8 @@ Return number of occurrences of value. [clinic start generated code]*/ static PyObject * -tuple_count(PyTupleObject *self, PyObject *value) -/*[clinic end generated code: output=aa927affc5a97605 input=531721aff65bd772]*/ +tuple_count_impl(PyTupleObject *self, PyObject *value) +/*[clinic end generated code: output=cf02888d4bc15d7a input=531721aff65bd772]*/ { Py_ssize_t count = 0; Py_ssize_t i; diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c index ace079dfef199b..118d2546b818e6 100644 --- a/Objects/typevarobject.c +++ b/Objects/typevarobject.c @@ -749,8 +749,8 @@ typevar.__typing_subst__ as typevar_typing_subst [clinic start generated code]*/ static PyObject * -typevar_typing_subst(typevarobject *self, PyObject *arg) -/*[clinic end generated code: output=0773735e8ce18968 input=9e87b57f0fc59b92]*/ +typevar_typing_subst_impl(typevarobject *self, PyObject *arg) +/*[clinic end generated code: output=c76ced134ed8f4e1 input=9e87b57f0fc59b92]*/ { PyObject *args[2] = {(PyObject *)self, arg}; PyObject *result = call_typing_func_object("_typevar_subst", args, 2); @@ -1358,8 +1358,8 @@ paramspec.__typing_subst__ as paramspec_typing_subst [clinic start generated code]*/ static PyObject * -paramspec_typing_subst(paramspecobject *self, PyObject *arg) -/*[clinic end generated code: output=4c5b4aaada1c5814 input=2d5b5e3d4a717189]*/ +paramspec_typing_subst_impl(paramspecobject *self, PyObject *arg) +/*[clinic end generated code: output=803e1ade3f13b57d input=2d5b5e3d4a717189]*/ { PyObject *args[2] = {(PyObject *)self, arg}; PyObject *result = call_typing_func_object("_paramspec_subst", args, 2); @@ -1612,8 +1612,8 @@ typevartuple.__typing_subst__ as typevartuple_typing_subst [clinic start generated code]*/ static PyObject * -typevartuple_typing_subst(typevartupleobject *self, PyObject *arg) -/*[clinic end generated code: output=237054c6d7484eea input=3fcf2dfd9eee7945]*/ +typevartuple_typing_subst_impl(typevartupleobject *self, PyObject *arg) +/*[clinic end generated code: output=814316519441cd76 input=3fcf2dfd9eee7945]*/ { PyErr_SetString(PyExc_TypeError, "Substitution of bare TypeVarTuple is not supported"); return NULL; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index cc6dc6dfead239..c5455bef59a655 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1303,8 +1303,8 @@ This is guaranteed to be unique among simultaneously existing objects. [clinic start generated code]*/ static PyObject * -builtin_id(PyModuleDef *self, PyObject *v) -/*[clinic end generated code: output=0aa640785f697f65 input=5a534136419631f4]*/ +builtin_id_impl(PyModuleDef *self, PyObject *v) +/*[clinic end generated code: output=4908a6782ed343e9 input=5a534136419631f4]*/ { PyObject *id = PyLong_FromVoidPtr(v); diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 7d348dbebed385..e5f634e34cb32f 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -628,6 +628,19 @@ PyDoc_STRVAR(builtin_id__doc__, #define BUILTIN_ID_METHODDEF \ {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, +static PyObject * +builtin_id_impl(PyModuleDef *self, PyObject *v); + +static PyObject * +builtin_id(PyObject *self, PyObject *v) +{ + PyObject *return_value = NULL; + + return_value = builtin_id_impl((PyModuleDef *)self, v); + + return return_value; +} + PyDoc_STRVAR(builtin_setattr__doc__, "setattr($module, obj, name, value, /)\n" "--\n" @@ -1239,4 +1252,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=b0178189d13e8bf8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c08e0e086a791ff0 input=a9049054013a1b77]*/ diff --git a/Python/clinic/context.c.h b/Python/clinic/context.c.h index 0adde76d7c3cb1..5ed74e6e6ddb6b 100644 --- a/Python/clinic/context.c.h +++ b/Python/clinic/context.c.h @@ -168,6 +168,19 @@ PyDoc_STRVAR(_contextvars_ContextVar_set__doc__, #define _CONTEXTVARS_CONTEXTVAR_SET_METHODDEF \ {"set", (PyCFunction)_contextvars_ContextVar_set, METH_O, _contextvars_ContextVar_set__doc__}, +static PyObject * +_contextvars_ContextVar_set_impl(PyContextVar *self, PyObject *value); + +static PyObject * +_contextvars_ContextVar_set(PyObject *self, PyObject *value) +{ + PyObject *return_value = NULL; + + return_value = _contextvars_ContextVar_set_impl((PyContextVar *)self, value); + + return return_value; +} + PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__, "reset($self, token, /)\n" "--\n" @@ -180,6 +193,19 @@ PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__, #define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF \ {"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__}, +static PyObject * +_contextvars_ContextVar_reset_impl(PyContextVar *self, PyObject *token); + +static PyObject * +_contextvars_ContextVar_reset(PyObject *self, PyObject *token) +{ + PyObject *return_value = NULL; + + return_value = _contextvars_ContextVar_reset_impl((PyContextVar *)self, token); + + return return_value; +} + PyDoc_STRVAR(token_enter__doc__, "__enter__($self, /)\n" "--\n" @@ -230,4 +256,4 @@ token_exit(PyObject *self, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=01987cdbf68a951a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3a04b2fddf24c3e9 input=a9049054013a1b77]*/ diff --git a/Python/context.c b/Python/context.c index dfdde7d1fa723f..4110e6891a1070 100644 --- a/Python/context.c +++ b/Python/context.c @@ -1058,8 +1058,8 @@ value via the `ContextVar.reset()` method. [clinic start generated code]*/ static PyObject * -_contextvars_ContextVar_set(PyContextVar *self, PyObject *value) -/*[clinic end generated code: output=446ed5e820d6d60b input=c0a6887154227453]*/ +_contextvars_ContextVar_set_impl(PyContextVar *self, PyObject *value) +/*[clinic end generated code: output=1b562d35cc79c806 input=c0a6887154227453]*/ { return PyContextVar_Set((PyObject *)self, value); } @@ -1076,8 +1076,8 @@ created the token was used. [clinic start generated code]*/ static PyObject * -_contextvars_ContextVar_reset(PyContextVar *self, PyObject *token) -/*[clinic end generated code: output=d4ee34d0742d62ee input=ebe2881e5af4ffda]*/ +_contextvars_ContextVar_reset_impl(PyContextVar *self, PyObject *token) +/*[clinic end generated code: output=3205d2bdff568521 input=ebe2881e5af4ffda]*/ { if (!PyContextToken_CheckExact(token)) { PyErr_Format(PyExc_TypeError, diff --git a/Tools/clinic/libclinic/clanguage.py b/Tools/clinic/libclinic/clanguage.py index 32d2c045b06bca..9e7fa7a7f58f95 100644 --- a/Tools/clinic/libclinic/clanguage.py +++ b/Tools/clinic/libclinic/clanguage.py @@ -423,14 +423,14 @@ def render_function( # HACK # when we're METH_O, but have a custom return converter, - # we use "impl_parameters" for the parsing function + # we use "parser_parameters" for the parsing function # because that works better. but that means we must # suppress actually declaring the impl's parameters # as variables in the parsing function. but since it's # METH_O, we have exactly one anyway, so we know exactly # where it is. if ("METH_O" in templates['methoddef_define'] and - '{impl_parameters}' in templates['parser_prototype']): + '{parser_parameters}' in templates['parser_prototype']): data.declarations.pop(0) full_name = f.full_name @@ -475,6 +475,7 @@ def render_function( else: template_dict['parse_arguments_comma'] = ''; template_dict['impl_parameters'] = ", ".join(data.impl_parameters) + template_dict['parser_parameters'] = ", ".join(data.impl_parameters[1:]) template_dict['impl_arguments'] = ", ".join(data.impl_arguments) template_dict['return_conversion'] = libclinic.format_escape("".join(data.return_conversion).rstrip()) diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/libclinic/converters.py index 2998eb519648aa..29828c08af07b1 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/libclinic/converters.py @@ -60,6 +60,7 @@ class defining_class_converter(CConverter): type = 'PyTypeObject *' format_unit = '' show_in_signature = False + specified_type: str | None = None def converter_init(self, *, type: str | None = None) -> None: self.specified_type = type @@ -1126,6 +1127,7 @@ class self_converter(CConverter): """ type: str | None = None format_unit = '' + specified_type: str | None = None def converter_init(self, *, type: str | None = None) -> None: self.specified_type = type diff --git a/Tools/clinic/libclinic/parse_args.py b/Tools/clinic/libclinic/parse_args.py index ff4731e99b98d4..b3fb765e31af47 100644 --- a/Tools/clinic/libclinic/parse_args.py +++ b/Tools/clinic/libclinic/parse_args.py @@ -134,7 +134,7 @@ def declare_parser( """) METH_O_PROTOTYPE: Final[str] = libclinic.normalize_snippet(""" static PyObject * - {c_basename}({impl_parameters}) + {c_basename}({self_type}{self_name}, {parser_parameters}) """) DOCSTRING_PROTOTYPE_VAR: Final[str] = libclinic.normalize_snippet(""" PyDoc_VAR({c_basename}__doc__); @@ -195,6 +195,7 @@ class ParseArgsCodeGen: # Function parameters parameters: list[Parameter] + self_parameter_converter: self_converter converters: list[CConverter] # Is 'defining_class' used for the first parameter? @@ -236,9 +237,10 @@ def __init__(self, func: Function, codegen: CodeGen) -> None: self.codegen = codegen self.parameters = list(self.func.parameters.values()) - first_param = self.parameters.pop(0) - if not isinstance(first_param.converter, self_converter): + self_parameter = self.parameters.pop(0) + if not isinstance(self_parameter.converter, self_converter): raise ValueError("the first parameter must use self_converter") + self.self_parameter_converter = self_parameter.converter self.requires_defining_class = False if self.parameters and isinstance(self.parameters[0].converter, defining_class_converter): @@ -293,6 +295,11 @@ def use_simple_return(self) -> bool: return (self.func.return_converter.type == 'PyObject *' and not self.func.critical_section) + def use_pyobject_self(self) -> bool: + pyobject_types = ('PyObject *', None) + return (self.self_parameter_converter.type in pyobject_types + and self.self_parameter_converter.specified_type in pyobject_types) + def select_prototypes(self) -> None: self.docstring_prototype = '' self.docstring_definition = '' @@ -403,7 +410,7 @@ def parse_one_arg(self) -> None: self.converters[0].format_unit == 'O'): meth_o_prototype = METH_O_PROTOTYPE - if self.use_simple_return(): + if self.use_simple_return() and self.use_pyobject_self(): # maps perfectly to METH_O, doesn't need a return converter. # so we skip making a parse function # and call directly into the impl function. From e0bc9d2a0c448cf46df233f8d84344c1f55a190f Mon Sep 17 00:00:00 2001 From: Gerardwx Date: Tue, 11 Mar 2025 12:45:31 -0400 Subject: [PATCH 2/7] =?UTF-8?q?Replace=20link=20to=20historical=20TypedDic?= =?UTF-8?q?t=20PEP=20with=20current=20document=20on=20typing.python?= =?UTF-8?q?=E2=80=A6=20(#131096)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Replace link to historical PEP with current document on typing.python.org * Update Doc/library/typing.rst Co-authored-by: Ned Batchelder --------- Co-authored-by: Ned Batchelder --- Doc/library/typing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 3bbc8c0e818975..6d5ee75f11efa7 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2771,7 +2771,7 @@ types. .. versionadded:: 3.13 - See :pep:`589` for more examples and detailed rules of using ``TypedDict``. + See the `TypedDict `_ section in the typing documentation for more examples and detailed rules. .. versionadded:: 3.8 From 3569e4a670bc6a02f1bb1baf08ecfb85c63755fb Mon Sep 17 00:00:00 2001 From: Barney Gale Date: Tue, 11 Mar 2025 18:01:43 +0000 Subject: [PATCH 3/7] GH-130614: pathlib ABCs: revise test suite for Windows path joining (#131016) Test Windows-flavoured `pathlib.types._JoinablePath` in a dedicated test module. These tests cover `LexicalWindowsPath`, `PureWindowsPath` and `WindowsPath`, where `LexicalWindowsPath` is a simple implementation of `_JoinablePath` for use in tests. --- Lib/test/test_pathlib/support/lexical_path.py | 6 + Lib/test/test_pathlib/test_join_windows.py | 290 ++++++++++++++++++ Lib/test/test_pathlib/test_pathlib.py | 24 ++ Lib/test/test_pathlib/test_pathlib_abc.py | 279 ----------------- 4 files changed, 320 insertions(+), 279 deletions(-) create mode 100644 Lib/test/test_pathlib/test_join_windows.py diff --git a/Lib/test/test_pathlib/support/lexical_path.py b/Lib/test/test_pathlib/support/lexical_path.py index 27dec30d0bdd5a..6298513de6cf83 100644 --- a/Lib/test/test_pathlib/support/lexical_path.py +++ b/Lib/test/test_pathlib/support/lexical_path.py @@ -2,6 +2,7 @@ Simple implementation of JoinablePath, for use in pathlib tests. """ +import ntpath import os.path import pathlib.types import posixpath @@ -37,3 +38,8 @@ def with_segments(self, *pathsegments): class LexicalPosixPath(LexicalPath): __slots__ = () parser = posixpath + + +class LexicalWindowsPath(LexicalPath): + __slots__ = () + parser = ntpath diff --git a/Lib/test/test_pathlib/test_join_windows.py b/Lib/test/test_pathlib/test_join_windows.py new file mode 100644 index 00000000000000..783248d1697eef --- /dev/null +++ b/Lib/test/test_pathlib/test_join_windows.py @@ -0,0 +1,290 @@ +""" +Tests for Windows-flavoured pathlib.types._JoinablePath +""" + +import os +import unittest + +from pathlib import PureWindowsPath, WindowsPath +from test.test_pathlib.support.lexical_path import LexicalWindowsPath + + +class JoinTestBase: + def test_join(self): + P = self.cls + p = P('C:/a/b') + pp = p.joinpath('x/y') + self.assertEqual(pp, P(r'C:/a/b\x/y')) + pp = p.joinpath('/x/y') + self.assertEqual(pp, P('C:/x/y')) + # Joining with a different drive => the first path is ignored, even + # if the second path is relative. + pp = p.joinpath('D:x/y') + self.assertEqual(pp, P('D:x/y')) + pp = p.joinpath('D:/x/y') + self.assertEqual(pp, P('D:/x/y')) + pp = p.joinpath('//host/share/x/y') + self.assertEqual(pp, P('//host/share/x/y')) + # Joining with the same drive => the first path is appended to if + # the second path is relative. + pp = p.joinpath('c:x/y') + self.assertEqual(pp, P(r'c:/a/b\x/y')) + pp = p.joinpath('c:/x/y') + self.assertEqual(pp, P('c:/x/y')) + # Joining with files with NTFS data streams => the filename should + # not be parsed as a drive letter + pp = p.joinpath('./d:s') + self.assertEqual(pp, P(r'C:/a/b\./d:s')) + pp = p.joinpath('./dd:s') + self.assertEqual(pp, P(r'C:/a/b\./dd:s')) + pp = p.joinpath('E:d:s') + self.assertEqual(pp, P('E:d:s')) + # Joining onto a UNC path with no root + pp = P('//').joinpath('server') + self.assertEqual(pp, P('//server')) + pp = P('//server').joinpath('share') + self.assertEqual(pp, P(r'//server\share')) + pp = P('//./BootPartition').joinpath('Windows') + self.assertEqual(pp, P(r'//./BootPartition\Windows')) + + def test_div(self): + # Basically the same as joinpath(). + P = self.cls + p = P('C:/a/b') + self.assertEqual(p / 'x/y', P(r'C:/a/b\x/y')) + self.assertEqual(p / 'x' / 'y', P(r'C:/a/b\x\y')) + self.assertEqual(p / '/x/y', P('C:/x/y')) + self.assertEqual(p / '/x' / 'y', P('C:/x\y')) + # Joining with a different drive => the first path is ignored, even + # if the second path is relative. + self.assertEqual(p / 'D:x/y', P('D:x/y')) + self.assertEqual(p / 'D:' / 'x/y', P('D:x/y')) + self.assertEqual(p / 'D:/x/y', P('D:/x/y')) + self.assertEqual(p / 'D:' / '/x/y', P('D:/x/y')) + self.assertEqual(p / '//host/share/x/y', P('//host/share/x/y')) + # Joining with the same drive => the first path is appended to if + # the second path is relative. + self.assertEqual(p / 'c:x/y', P(r'c:/a/b\x/y')) + self.assertEqual(p / 'c:/x/y', P('c:/x/y')) + # Joining with files with NTFS data streams => the filename should + # not be parsed as a drive letter + self.assertEqual(p / './d:s', P(r'C:/a/b\./d:s')) + self.assertEqual(p / './dd:s', P(r'C:/a/b\./dd:s')) + self.assertEqual(p / 'E:d:s', P('E:d:s')) + + def test_str(self): + p = self.cls(r'a\b\c') + self.assertEqual(str(p), 'a\\b\\c') + p = self.cls(r'c:\a\b\c') + self.assertEqual(str(p), 'c:\\a\\b\\c') + p = self.cls('\\\\a\\b\\') + self.assertEqual(str(p), '\\\\a\\b\\') + p = self.cls(r'\\a\b\c') + self.assertEqual(str(p), '\\\\a\\b\\c') + p = self.cls(r'\\a\b\c\d') + self.assertEqual(str(p), '\\\\a\\b\\c\\d') + + def test_parts(self): + P = self.cls + p = P(r'c:a\b') + parts = p.parts + self.assertEqual(parts, ('c:', 'a', 'b')) + p = P(r'c:\a\b') + parts = p.parts + self.assertEqual(parts, ('c:\\', 'a', 'b')) + p = P(r'\\a\b\c\d') + parts = p.parts + self.assertEqual(parts, ('\\\\a\\b\\', 'c', 'd')) + + def test_parent(self): + # Anchored + P = self.cls + p = P('z:a/b/c') + self.assertEqual(p.parent, P('z:a/b')) + self.assertEqual(p.parent.parent, P('z:a')) + self.assertEqual(p.parent.parent.parent, P('z:')) + self.assertEqual(p.parent.parent.parent.parent, P('z:')) + p = P('z:/a/b/c') + self.assertEqual(p.parent, P('z:/a/b')) + self.assertEqual(p.parent.parent, P('z:/a')) + self.assertEqual(p.parent.parent.parent, P('z:/')) + self.assertEqual(p.parent.parent.parent.parent, P('z:/')) + p = P('//a/b/c/d') + self.assertEqual(p.parent, P('//a/b/c')) + self.assertEqual(p.parent.parent, P('//a/b/')) + self.assertEqual(p.parent.parent.parent, P('//a/b/')) + + def test_parents(self): + # Anchored + P = self.cls + p = P('z:a/b') + par = p.parents + self.assertEqual(len(par), 2) + self.assertEqual(par[0], P('z:a')) + self.assertEqual(par[1], P('z:')) + self.assertEqual(par[0:1], (P('z:a'),)) + self.assertEqual(par[:-1], (P('z:a'),)) + self.assertEqual(par[:2], (P('z:a'), P('z:'))) + self.assertEqual(par[1:], (P('z:'),)) + self.assertEqual(par[::2], (P('z:a'),)) + self.assertEqual(par[::-1], (P('z:'), P('z:a'))) + self.assertEqual(list(par), [P('z:a'), P('z:')]) + with self.assertRaises(IndexError): + par[2] + p = P('z:/a/b') + par = p.parents + self.assertEqual(len(par), 2) + self.assertEqual(par[0], P('z:/a')) + self.assertEqual(par[1], P('z:/')) + self.assertEqual(par[0:1], (P('z:/a'),)) + self.assertEqual(par[0:-1], (P('z:/a'),)) + self.assertEqual(par[:2], (P('z:/a'), P('z:/'))) + self.assertEqual(par[1:], (P('z:/'),)) + self.assertEqual(par[::2], (P('z:/a'),)) + self.assertEqual(par[::-1], (P('z:/'), P('z:/a'),)) + self.assertEqual(list(par), [P('z:/a'), P('z:/')]) + with self.assertRaises(IndexError): + par[2] + p = P('//a/b/c/d') + par = p.parents + self.assertEqual(len(par), 2) + self.assertEqual(par[0], P('//a/b/c')) + self.assertEqual(par[1], P('//a/b/')) + self.assertEqual(par[0:1], (P('//a/b/c'),)) + self.assertEqual(par[0:-1], (P('//a/b/c'),)) + self.assertEqual(par[:2], (P('//a/b/c'), P('//a/b/'))) + self.assertEqual(par[1:], (P('//a/b/'),)) + self.assertEqual(par[::2], (P('//a/b/c'),)) + self.assertEqual(par[::-1], (P('//a/b/'), P('//a/b/c'))) + self.assertEqual(list(par), [P('//a/b/c'), P('//a/b/')]) + with self.assertRaises(IndexError): + par[2] + + def test_anchor(self): + P = self.cls + self.assertEqual(P('c:').anchor, 'c:') + self.assertEqual(P('c:a/b').anchor, 'c:') + self.assertEqual(P('c:\\').anchor, 'c:\\') + self.assertEqual(P('c:\\a\\b\\').anchor, 'c:\\') + self.assertEqual(P('\\\\a\\b\\').anchor, '\\\\a\\b\\') + self.assertEqual(P('\\\\a\\b\\c\\d').anchor, '\\\\a\\b\\') + + def test_name(self): + P = self.cls + self.assertEqual(P('c:').name, '') + self.assertEqual(P('c:/').name, '') + self.assertEqual(P('c:a/b').name, 'b') + self.assertEqual(P('c:/a/b').name, 'b') + self.assertEqual(P('c:a/b.py').name, 'b.py') + self.assertEqual(P('c:/a/b.py').name, 'b.py') + self.assertEqual(P('//My.py/Share.php').name, '') + self.assertEqual(P('//My.py/Share.php/a/b').name, 'b') + + def test_stem(self): + P = self.cls + self.assertEqual(P('c:').stem, '') + self.assertEqual(P('c:..').stem, '..') + self.assertEqual(P('c:/').stem, '') + self.assertEqual(P('c:a/b').stem, 'b') + self.assertEqual(P('c:a/b.py').stem, 'b') + self.assertEqual(P('c:a/.hgrc').stem, '.hgrc') + self.assertEqual(P('c:a/.hg.rc').stem, '.hg') + self.assertEqual(P('c:a/b.tar.gz').stem, 'b.tar') + self.assertEqual(P('c:a/trailing.dot.').stem, 'trailing.dot') + + def test_suffix(self): + P = self.cls + self.assertEqual(P('c:').suffix, '') + self.assertEqual(P('c:/').suffix, '') + self.assertEqual(P('c:a/b').suffix, '') + self.assertEqual(P('c:/a/b').suffix, '') + self.assertEqual(P('c:a/b.py').suffix, '.py') + self.assertEqual(P('c:/a/b.py').suffix, '.py') + self.assertEqual(P('c:a/.hgrc').suffix, '') + self.assertEqual(P('c:/a/.hgrc').suffix, '') + self.assertEqual(P('c:a/.hg.rc').suffix, '.rc') + self.assertEqual(P('c:/a/.hg.rc').suffix, '.rc') + self.assertEqual(P('c:a/b.tar.gz').suffix, '.gz') + self.assertEqual(P('c:/a/b.tar.gz').suffix, '.gz') + self.assertEqual(P('c:a/trailing.dot.').suffix, '.') + self.assertEqual(P('c:/a/trailing.dot.').suffix, '.') + self.assertEqual(P('//My.py/Share.php').suffix, '') + self.assertEqual(P('//My.py/Share.php/a/b').suffix, '') + + def test_suffixes(self): + P = self.cls + self.assertEqual(P('c:').suffixes, []) + self.assertEqual(P('c:/').suffixes, []) + self.assertEqual(P('c:a/b').suffixes, []) + self.assertEqual(P('c:/a/b').suffixes, []) + self.assertEqual(P('c:a/b.py').suffixes, ['.py']) + self.assertEqual(P('c:/a/b.py').suffixes, ['.py']) + self.assertEqual(P('c:a/.hgrc').suffixes, []) + self.assertEqual(P('c:/a/.hgrc').suffixes, []) + self.assertEqual(P('c:a/.hg.rc').suffixes, ['.rc']) + self.assertEqual(P('c:/a/.hg.rc').suffixes, ['.rc']) + self.assertEqual(P('c:a/b.tar.gz').suffixes, ['.tar', '.gz']) + self.assertEqual(P('c:/a/b.tar.gz').suffixes, ['.tar', '.gz']) + self.assertEqual(P('//My.py/Share.php').suffixes, []) + self.assertEqual(P('//My.py/Share.php/a/b').suffixes, []) + self.assertEqual(P('c:a/trailing.dot.').suffixes, ['.dot', '.']) + self.assertEqual(P('c:/a/trailing.dot.').suffixes, ['.dot', '.']) + + def test_with_name(self): + P = self.cls + self.assertEqual(P(r'c:a\b').with_name('d.xml'), P(r'c:a\d.xml')) + self.assertEqual(P(r'c:\a\b').with_name('d.xml'), P(r'c:\a\d.xml')) + self.assertEqual(P(r'c:a\Dot ending.').with_name('d.xml'), P(r'c:a\d.xml')) + self.assertEqual(P(r'c:\a\Dot ending.').with_name('d.xml'), P(r'c:\a\d.xml')) + self.assertRaises(ValueError, P(r'c:a\b').with_name, r'd:\e') + self.assertRaises(ValueError, P(r'c:a\b').with_name, r'\\My\Share') + + def test_with_stem(self): + P = self.cls + self.assertEqual(P('c:a/b').with_stem('d'), P('c:a/d')) + self.assertEqual(P('c:/a/b').with_stem('d'), P('c:/a/d')) + self.assertEqual(P('c:a/Dot ending.').with_stem('d'), P('c:a/d.')) + self.assertEqual(P('c:/a/Dot ending.').with_stem('d'), P('c:/a/d.')) + self.assertRaises(ValueError, P('c:a/b').with_stem, 'd:/e') + self.assertRaises(ValueError, P('c:a/b').with_stem, '//My/Share') + + def test_with_suffix(self): + P = self.cls + self.assertEqual(P('c:a/b').with_suffix('.gz'), P('c:a/b.gz')) + self.assertEqual(P('c:/a/b').with_suffix('.gz'), P('c:/a/b.gz')) + self.assertEqual(P('c:a/b.py').with_suffix('.gz'), P('c:a/b.gz')) + self.assertEqual(P('c:/a/b.py').with_suffix('.gz'), P('c:/a/b.gz')) + # Path doesn't have a "filename" component. + self.assertRaises(ValueError, P('').with_suffix, '.gz') + self.assertRaises(ValueError, P('/').with_suffix, '.gz') + self.assertRaises(ValueError, P('//My/Share').with_suffix, '.gz') + # Invalid suffix. + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '/') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '\\') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c:') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '/.gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '\\.gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c:.gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c/d') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c\\d') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '.c/d') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '.c\\d') + self.assertRaises(TypeError, P('c:a/b').with_suffix, None) + + +class LexicalWindowsPathJoinTest(JoinTestBase, unittest.TestCase): + cls = LexicalWindowsPath + + +class PureWindowsPathJoinTest(JoinTestBase, unittest.TestCase): + cls = PureWindowsPath + + +if os.name == 'nt': + class WindowsPathJoinTest(JoinTestBase, unittest.TestCase): + cls = WindowsPath + + +if __name__ == "__main__": + unittest.main() diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 1996bbb65a304b..aff155cf1100bb 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -411,6 +411,18 @@ def test_stem_empty(self): self.assertEqual(P('').stem, '') self.assertEqual(P('.').stem, '') + @needs_windows + def test_with_name_windows(self): + P = self.cls + self.assertRaises(ValueError, P(r'c:').with_name, 'd.xml') + self.assertRaises(ValueError, P(r'c:\\').with_name, 'd.xml') + self.assertRaises(ValueError, P(r'\\My\Share').with_name, 'd.xml') + # NTFS alternate data streams + self.assertEqual(str(P('a').with_name('d:')), '.\\d:') + self.assertEqual(str(P('a').with_name('d:e')), '.\\d:e') + self.assertEqual(P(r'c:a\b').with_name('d:'), P(r'c:a\d:')) + self.assertEqual(P(r'c:a\b').with_name('d:e'), P(r'c:a\d:e')) + def test_with_name_empty(self): P = self.cls self.assertRaises(ValueError, P('').with_name, 'd.xml') @@ -419,6 +431,18 @@ def test_with_name_empty(self): self.assertRaises(ValueError, P('a/b').with_name, '') self.assertRaises(ValueError, P('a/b').with_name, '.') + @needs_windows + def test_with_stem_windows(self): + P = self.cls + self.assertRaises(ValueError, P('c:').with_stem, 'd') + self.assertRaises(ValueError, P('c:/').with_stem, 'd') + self.assertRaises(ValueError, P('//My/Share').with_stem, 'd') + # NTFS alternate data streams + self.assertEqual(str(P('a').with_stem('d:')), '.\\d:') + self.assertEqual(str(P('a').with_stem('d:e')), '.\\d:e') + self.assertEqual(P('c:a/b').with_stem('d:'), P('c:a/d:')) + self.assertEqual(P('c:a/b').with_stem('d:e'), P('c:a/d:e')) + def test_with_stem_empty(self): P = self.cls self.assertRaises(ValueError, P('').with_stem, 'd') diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py index 779c8a60bece82..a93af961b503a1 100644 --- a/Lib/test/test_pathlib/test_pathlib_abc.py +++ b/Lib/test/test_pathlib/test_pathlib_abc.py @@ -108,70 +108,6 @@ def test_str_subclass_windows(self): self._check_str_subclass('\\\\some\\share\\a') self._check_str_subclass('\\\\some\\share\\a\\b.txt') - @needs_windows - def test_join_windows(self): - P = self.cls - p = P('C:/a/b') - pp = p.joinpath('x/y') - self.assertEqual(pp, P('C:/a/b/x/y')) - pp = p.joinpath('/x/y') - self.assertEqual(pp, P('C:/x/y')) - # Joining with a different drive => the first path is ignored, even - # if the second path is relative. - pp = p.joinpath('D:x/y') - self.assertEqual(pp, P('D:x/y')) - pp = p.joinpath('D:/x/y') - self.assertEqual(pp, P('D:/x/y')) - pp = p.joinpath('//host/share/x/y') - self.assertEqual(pp, P('//host/share/x/y')) - # Joining with the same drive => the first path is appended to if - # the second path is relative. - pp = p.joinpath('c:x/y') - self.assertEqual(pp, P('C:/a/b/x/y')) - pp = p.joinpath('c:/x/y') - self.assertEqual(pp, P('C:/x/y')) - # Joining with files with NTFS data streams => the filename should - # not be parsed as a drive letter - pp = p.joinpath(P('./d:s')) - self.assertEqual(pp, P('C:/a/b/d:s')) - pp = p.joinpath(P('./dd:s')) - self.assertEqual(pp, P('C:/a/b/dd:s')) - pp = p.joinpath(P('E:d:s')) - self.assertEqual(pp, P('E:d:s')) - # Joining onto a UNC path with no root - pp = P('//').joinpath('server') - self.assertEqual(pp, P('//server')) - pp = P('//server').joinpath('share') - self.assertEqual(pp, P('//server/share')) - pp = P('//./BootPartition').joinpath('Windows') - self.assertEqual(pp, P('//./BootPartition/Windows')) - - @needs_windows - def test_div_windows(self): - # Basically the same as joinpath(). - P = self.cls - p = P('C:/a/b') - self.assertEqual(p / 'x/y', P('C:/a/b/x/y')) - self.assertEqual(p / 'x' / 'y', P('C:/a/b/x/y')) - self.assertEqual(p / '/x/y', P('C:/x/y')) - self.assertEqual(p / '/x' / 'y', P('C:/x/y')) - # Joining with a different drive => the first path is ignored, even - # if the second path is relative. - self.assertEqual(p / 'D:x/y', P('D:x/y')) - self.assertEqual(p / 'D:' / 'x/y', P('D:x/y')) - self.assertEqual(p / 'D:/x/y', P('D:/x/y')) - self.assertEqual(p / 'D:' / '/x/y', P('D:/x/y')) - self.assertEqual(p / '//host/share/x/y', P('//host/share/x/y')) - # Joining with the same drive => the first path is appended to if - # the second path is relative. - self.assertEqual(p / 'c:x/y', P('C:/a/b/x/y')) - self.assertEqual(p / 'c:/x/y', P('C:/x/y')) - # Joining with files with NTFS data streams => the filename should - # not be parsed as a drive letter - self.assertEqual(p / P('./d:s'), P('C:/a/b/d:s')) - self.assertEqual(p / P('./dd:s'), P('C:/a/b/dd:s')) - self.assertEqual(p / P('E:d:s'), P('E:d:s')) - def _check_str(self, expected, args): p = self.cls(*args) self.assertEqual(str(p), expected.replace('/', self.sep)) @@ -195,221 +131,6 @@ def test_str_windows(self): p = self.cls('//a/b/c/d') self.assertEqual(str(p), '\\\\a\\b\\c\\d') - @needs_windows - def test_parts_windows(self): - P = self.cls - p = P('c:a/b') - parts = p.parts - self.assertEqual(parts, ('c:', 'a', 'b')) - p = P('c:/a/b') - parts = p.parts - self.assertEqual(parts, ('c:\\', 'a', 'b')) - p = P('//a/b/c/d') - parts = p.parts - self.assertEqual(parts, ('\\\\a\\b\\', 'c', 'd')) - - @needs_windows - def test_parent_windows(self): - # Anchored - P = self.cls - p = P('z:a/b/c') - self.assertEqual(p.parent, P('z:a/b')) - self.assertEqual(p.parent.parent, P('z:a')) - self.assertEqual(p.parent.parent.parent, P('z:')) - self.assertEqual(p.parent.parent.parent.parent, P('z:')) - p = P('z:/a/b/c') - self.assertEqual(p.parent, P('z:/a/b')) - self.assertEqual(p.parent.parent, P('z:/a')) - self.assertEqual(p.parent.parent.parent, P('z:/')) - self.assertEqual(p.parent.parent.parent.parent, P('z:/')) - p = P('//a/b/c/d') - self.assertEqual(p.parent, P('//a/b/c')) - self.assertEqual(p.parent.parent, P('//a/b')) - self.assertEqual(p.parent.parent.parent, P('//a/b')) - - @needs_windows - def test_parents_windows(self): - # Anchored - P = self.cls - p = P('z:a/b/') - par = p.parents - self.assertEqual(len(par), 2) - self.assertEqual(par[0], P('z:a')) - self.assertEqual(par[1], P('z:')) - self.assertEqual(par[0:1], (P('z:a'),)) - self.assertEqual(par[:-1], (P('z:a'),)) - self.assertEqual(par[:2], (P('z:a'), P('z:'))) - self.assertEqual(par[1:], (P('z:'),)) - self.assertEqual(par[::2], (P('z:a'),)) - self.assertEqual(par[::-1], (P('z:'), P('z:a'))) - self.assertEqual(list(par), [P('z:a'), P('z:')]) - with self.assertRaises(IndexError): - par[2] - p = P('z:/a/b/') - par = p.parents - self.assertEqual(len(par), 2) - self.assertEqual(par[0], P('z:/a')) - self.assertEqual(par[1], P('z:/')) - self.assertEqual(par[0:1], (P('z:/a'),)) - self.assertEqual(par[0:-1], (P('z:/a'),)) - self.assertEqual(par[:2], (P('z:/a'), P('z:/'))) - self.assertEqual(par[1:], (P('z:/'),)) - self.assertEqual(par[::2], (P('z:/a'),)) - self.assertEqual(par[::-1], (P('z:/'), P('z:/a'),)) - self.assertEqual(list(par), [P('z:/a'), P('z:/')]) - with self.assertRaises(IndexError): - par[2] - p = P('//a/b/c/d') - par = p.parents - self.assertEqual(len(par), 2) - self.assertEqual(par[0], P('//a/b/c')) - self.assertEqual(par[1], P('//a/b')) - self.assertEqual(par[0:1], (P('//a/b/c'),)) - self.assertEqual(par[0:-1], (P('//a/b/c'),)) - self.assertEqual(par[:2], (P('//a/b/c'), P('//a/b'))) - self.assertEqual(par[1:], (P('//a/b'),)) - self.assertEqual(par[::2], (P('//a/b/c'),)) - self.assertEqual(par[::-1], (P('//a/b'), P('//a/b/c'))) - self.assertEqual(list(par), [P('//a/b/c'), P('//a/b')]) - with self.assertRaises(IndexError): - par[2] - - @needs_windows - def test_anchor_windows(self): - P = self.cls - self.assertEqual(P('c:').anchor, 'c:') - self.assertEqual(P('c:a/b').anchor, 'c:') - self.assertEqual(P('c:/').anchor, 'c:\\') - self.assertEqual(P('c:/a/b/').anchor, 'c:\\') - self.assertEqual(P('//a/b').anchor, '\\\\a\\b\\') - self.assertEqual(P('//a/b/').anchor, '\\\\a\\b\\') - self.assertEqual(P('//a/b/c/d').anchor, '\\\\a\\b\\') - - @needs_windows - def test_name_windows(self): - P = self.cls - self.assertEqual(P('c:').name, '') - self.assertEqual(P('c:/').name, '') - self.assertEqual(P('c:a/b').name, 'b') - self.assertEqual(P('c:/a/b').name, 'b') - self.assertEqual(P('c:a/b.py').name, 'b.py') - self.assertEqual(P('c:/a/b.py').name, 'b.py') - self.assertEqual(P('//My.py/Share.php').name, '') - self.assertEqual(P('//My.py/Share.php/a/b').name, 'b') - - @needs_windows - def test_suffix_windows(self): - P = self.cls - self.assertEqual(P('c:').suffix, '') - self.assertEqual(P('c:/').suffix, '') - self.assertEqual(P('c:a/b').suffix, '') - self.assertEqual(P('c:/a/b').suffix, '') - self.assertEqual(P('c:a/b.py').suffix, '.py') - self.assertEqual(P('c:/a/b.py').suffix, '.py') - self.assertEqual(P('c:a/.hgrc').suffix, '') - self.assertEqual(P('c:/a/.hgrc').suffix, '') - self.assertEqual(P('c:a/.hg.rc').suffix, '.rc') - self.assertEqual(P('c:/a/.hg.rc').suffix, '.rc') - self.assertEqual(P('c:a/b.tar.gz').suffix, '.gz') - self.assertEqual(P('c:/a/b.tar.gz').suffix, '.gz') - self.assertEqual(P('c:a/trailing.dot.').suffix, '.') - self.assertEqual(P('c:/a/trailing.dot.').suffix, '.') - self.assertEqual(P('//My.py/Share.php').suffix, '') - self.assertEqual(P('//My.py/Share.php/a/b').suffix, '') - - @needs_windows - def test_suffixes_windows(self): - P = self.cls - self.assertEqual(P('c:').suffixes, []) - self.assertEqual(P('c:/').suffixes, []) - self.assertEqual(P('c:a/b').suffixes, []) - self.assertEqual(P('c:/a/b').suffixes, []) - self.assertEqual(P('c:a/b.py').suffixes, ['.py']) - self.assertEqual(P('c:/a/b.py').suffixes, ['.py']) - self.assertEqual(P('c:a/.hgrc').suffixes, []) - self.assertEqual(P('c:/a/.hgrc').suffixes, []) - self.assertEqual(P('c:a/.hg.rc').suffixes, ['.rc']) - self.assertEqual(P('c:/a/.hg.rc').suffixes, ['.rc']) - self.assertEqual(P('c:a/b.tar.gz').suffixes, ['.tar', '.gz']) - self.assertEqual(P('c:/a/b.tar.gz').suffixes, ['.tar', '.gz']) - self.assertEqual(P('//My.py/Share.php').suffixes, []) - self.assertEqual(P('//My.py/Share.php/a/b').suffixes, []) - self.assertEqual(P('c:a/trailing.dot.').suffixes, ['.dot', '.']) - self.assertEqual(P('c:/a/trailing.dot.').suffixes, ['.dot', '.']) - - @needs_windows - def test_stem_windows(self): - P = self.cls - self.assertEqual(P('c:').stem, '') - self.assertEqual(P('c:.').stem, '') - self.assertEqual(P('c:..').stem, '..') - self.assertEqual(P('c:/').stem, '') - self.assertEqual(P('c:a/b').stem, 'b') - self.assertEqual(P('c:a/b.py').stem, 'b') - self.assertEqual(P('c:a/.hgrc').stem, '.hgrc') - self.assertEqual(P('c:a/.hg.rc').stem, '.hg') - self.assertEqual(P('c:a/b.tar.gz').stem, 'b.tar') - self.assertEqual(P('c:a/trailing.dot.').stem, 'trailing.dot') - - @needs_windows - def test_with_name_windows(self): - P = self.cls - self.assertEqual(P('c:a/b').with_name('d.xml'), P('c:a/d.xml')) - self.assertEqual(P('c:/a/b').with_name('d.xml'), P('c:/a/d.xml')) - self.assertEqual(P('c:a/Dot ending.').with_name('d.xml'), P('c:a/d.xml')) - self.assertEqual(P('c:/a/Dot ending.').with_name('d.xml'), P('c:/a/d.xml')) - self.assertRaises(ValueError, P('c:').with_name, 'd.xml') - self.assertRaises(ValueError, P('c:/').with_name, 'd.xml') - self.assertRaises(ValueError, P('//My/Share').with_name, 'd.xml') - self.assertEqual(str(P('a').with_name('d:')), '.\\d:') - self.assertEqual(str(P('a').with_name('d:e')), '.\\d:e') - self.assertEqual(P('c:a/b').with_name('d:'), P('c:a/d:')) - self.assertEqual(P('c:a/b').with_name('d:e'), P('c:a/d:e')) - self.assertRaises(ValueError, P('c:a/b').with_name, 'd:/e') - self.assertRaises(ValueError, P('c:a/b').with_name, '//My/Share') - - @needs_windows - def test_with_stem_windows(self): - P = self.cls - self.assertEqual(P('c:a/b').with_stem('d'), P('c:a/d')) - self.assertEqual(P('c:/a/b').with_stem('d'), P('c:/a/d')) - self.assertEqual(P('c:a/Dot ending.').with_stem('d'), P('c:a/d.')) - self.assertEqual(P('c:/a/Dot ending.').with_stem('d'), P('c:/a/d.')) - self.assertRaises(ValueError, P('c:').with_stem, 'd') - self.assertRaises(ValueError, P('c:/').with_stem, 'd') - self.assertRaises(ValueError, P('//My/Share').with_stem, 'd') - self.assertEqual(str(P('a').with_stem('d:')), '.\\d:') - self.assertEqual(str(P('a').with_stem('d:e')), '.\\d:e') - self.assertEqual(P('c:a/b').with_stem('d:'), P('c:a/d:')) - self.assertEqual(P('c:a/b').with_stem('d:e'), P('c:a/d:e')) - self.assertRaises(ValueError, P('c:a/b').with_stem, 'd:/e') - self.assertRaises(ValueError, P('c:a/b').with_stem, '//My/Share') - - @needs_windows - def test_with_suffix_windows(self): - P = self.cls - self.assertEqual(P('c:a/b').with_suffix('.gz'), P('c:a/b.gz')) - self.assertEqual(P('c:/a/b').with_suffix('.gz'), P('c:/a/b.gz')) - self.assertEqual(P('c:a/b.py').with_suffix('.gz'), P('c:a/b.gz')) - self.assertEqual(P('c:/a/b.py').with_suffix('.gz'), P('c:/a/b.gz')) - # Path doesn't have a "filename" component. - self.assertRaises(ValueError, P('').with_suffix, '.gz') - self.assertRaises(ValueError, P('.').with_suffix, '.gz') - self.assertRaises(ValueError, P('/').with_suffix, '.gz') - self.assertRaises(ValueError, P('//My/Share').with_suffix, '.gz') - # Invalid suffix. - self.assertRaises(ValueError, P('c:a/b').with_suffix, 'gz') - self.assertRaises(ValueError, P('c:a/b').with_suffix, '/') - self.assertRaises(ValueError, P('c:a/b').with_suffix, '\\') - self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c:') - self.assertRaises(ValueError, P('c:a/b').with_suffix, '/.gz') - self.assertRaises(ValueError, P('c:a/b').with_suffix, '\\.gz') - self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c:.gz') - self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c/d') - self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c\\d') - self.assertRaises(ValueError, P('c:a/b').with_suffix, '.c/d') - self.assertRaises(ValueError, P('c:a/b').with_suffix, '.c\\d') - self.assertRaises(TypeError, P('c:a/b').with_suffix, None) # # Tests for the virtual classes. From 8b1edae93a05cc90c5b8c5c935f3753aca938ccf Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 11 Mar 2025 14:04:22 -0400 Subject: [PATCH 4/7] gh-122029: Do not unpack method for legacy tracing anymore (#130898) --- Lib/test/test_sys_setprofile.py | 21 +++++++++++++++++++ ...-03-05-21-52-20.gh-issue-122029.d_z93q.rst | 1 + Python/legacy_tracing.c | 13 ------------ 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-03-05-21-52-20.gh-issue-122029.d_z93q.rst diff --git a/Lib/test/test_sys_setprofile.py b/Lib/test/test_sys_setprofile.py index 0753a9d8b8e0ee..345c022bd2374c 100644 --- a/Lib/test/test_sys_setprofile.py +++ b/Lib/test/test_sys_setprofile.py @@ -511,6 +511,27 @@ class B: ] ) + # Test CALL_FUNCTION_EX + events = [] + sys.setprofile(lambda frame, event, args: events.append(event)) + # Not important, we only want to trigger INSTRUMENTED_CALL_KW + args = (1,) + m = B().f + m(*args, key=lambda x: 0) + sys.setprofile(None) + # The last c_call is the call to sys.setprofile + # INSTRUMENTED_CALL_FUNCTION_EX has different behavior than the other + # instrumented call bytecodes, it does not unpack the callable before + # calling it. This is probably not ideal because it's not consistent, + # but at least we get a consistent call stack (no unmatched c_call). + self.assertEqual( + events, + ['call', 'return', + 'call', 'return', + 'c_call' + ] + ) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-05-21-52-20.gh-issue-122029.d_z93q.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-05-21-52-20.gh-issue-122029.d_z93q.rst new file mode 100644 index 00000000000000..6324f24d155389 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-05-21-52-20.gh-issue-122029.d_z93q.rst @@ -0,0 +1 @@ +:func:`sys.setprofile` and :func:`sys.settrace` will not generate a ``c_call`` event for ``INSTRUMENTED_CALL_FUNCTION_EX`` if the callable is a method with a C function wrapped, because we do not generate ``c_return`` event in such case. diff --git a/Python/legacy_tracing.c b/Python/legacy_tracing.c index 97634f9183c7d5..82465c66ab5231 100644 --- a/Python/legacy_tracing.c +++ b/Python/legacy_tracing.c @@ -121,19 +121,6 @@ sys_profile_call_or_return( Py_DECREF(meth); return res; } - else if (Py_TYPE(callable) == &PyMethod_Type) { - // CALL instruction will grab the function from the method, - // so if the function is a C function, the return event will - // be emitted. However, CALL event happens before CALL - // instruction, so we need to handle this case here. - PyObject* func = PyMethod_GET_FUNCTION(callable); - if (func == NULL) { - return NULL; - } - if (PyCFunction_Check(func)) { - return call_profile_func(self, func); - } - } Py_RETURN_NONE; } From fcf756adef43a15e5bc2b397d95ca8c6a54d524d Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Wed, 12 Mar 2025 01:21:53 +0530 Subject: [PATCH 5/7] fix various warnings in `test_asyncio.test_tasks` (#131109) --- Lib/test/test_asyncio/test_tasks.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 591b48b88a268c..f1a665e5df3fd3 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2301,16 +2301,19 @@ class Subclass(Task): def __del__(self): pass - async def coro(): + async def corofn(): await asyncio.sleep(0.01) - task = Subclass(coro(), loop = self.loop) + coro = corofn() + task = Subclass(coro, loop = self.loop) task._log_destroy_pending = False del task support.gc_collect() + coro.close() + @mock.patch('asyncio.base_events.logger') def test_tb_logger_not_called_after_cancel(self, m_log): loop = asyncio.new_event_loop() @@ -2716,12 +2719,12 @@ def __str__(self): coro = coroutine_function() with contextlib.closing(asyncio.EventLoop()) as loop: task = asyncio.Task.__new__(asyncio.Task) - for _ in range(5): with self.assertRaisesRegex(RuntimeError, 'break'): task.__init__(coro, loop=loop, context=obj, name=Break()) coro.close() + task._log_destroy_pending = False del task self.assertEqual(sys.getrefcount(obj), initial_refcount) From 24070492cfee2cd698009418f70cc3755dbd0b99 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Wed, 12 Mar 2025 01:33:44 +0530 Subject: [PATCH 6/7] gh-128002: add `test_asyncio.test_free_threading` to tsan tests (#131106) --- Lib/test/libregrtest/tsan.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/libregrtest/tsan.py b/Lib/test/libregrtest/tsan.py index 77dde5ecb076e2..4fb0ee5038f3a9 100644 --- a/Lib/test/libregrtest/tsan.py +++ b/Lib/test/libregrtest/tsan.py @@ -2,6 +2,7 @@ # chosen because they use threads and run in a reasonable amount of time. TSAN_TESTS = [ + 'test_asyncio.test_free_threading', # TODO: enable more of test_capi once bugs are fixed (GH-116908, GH-116909). 'test_capi.test_mem', 'test_capi.test_pyatomic', From ad90c5fabc415d4e46205947cceda82893ec1460 Mon Sep 17 00:00:00 2001 From: Barney Gale Date: Tue, 11 Mar 2025 20:54:22 +0000 Subject: [PATCH 7/7] GH-130614: pathlib ABCs: revise test suite for readable paths (#131018) Test `pathlib.types._ReadablePath` in a dedicated test module. These tests cover `ReadableZipPath`, `ReadableLocalPath` and `Path`, where the former two classes are implementations of `_ReadablePath` for use in tests. --- Lib/test/test_pathlib/support/local_path.py | 145 +++++++++ Lib/test/test_pathlib/support/zip_path.py | 278 ++++++++++++++++++ Lib/test/test_pathlib/test_pathlib.py | 27 ++ Lib/test/test_pathlib/test_pathlib_abc.py | 268 ----------------- Lib/test/test_pathlib/test_read.py | 309 ++++++++++++++++++++ 5 files changed, 759 insertions(+), 268 deletions(-) create mode 100644 Lib/test/test_pathlib/support/local_path.py create mode 100644 Lib/test/test_pathlib/support/zip_path.py create mode 100644 Lib/test/test_pathlib/test_read.py diff --git a/Lib/test/test_pathlib/support/local_path.py b/Lib/test/test_pathlib/support/local_path.py new file mode 100644 index 00000000000000..1d2b03df225978 --- /dev/null +++ b/Lib/test/test_pathlib/support/local_path.py @@ -0,0 +1,145 @@ +""" +Implementation of ReadablePath for local paths, for use in pathlib tests. + +LocalPathGround is also defined here. It helps establish the "ground truth" +about local paths in tests. +""" + +import os +import pathlib.types + +from test.support import os_helper +from test.test_pathlib.support.lexical_path import LexicalPath + + +class LocalPathGround: + can_symlink = os_helper.can_symlink() + + def __init__(self, path_cls): + self.path_cls = path_cls + + def setup(self, local_suffix=""): + root = self.path_cls(os_helper.TESTFN + local_suffix) + os.mkdir(root) + return root + + def teardown(self, root): + os_helper.rmtree(root) + + def create_file(self, p, data=b''): + with open(p, 'wb') as f: + f.write(data) + + def create_dir(self, p): + os.mkdir(p) + + def create_symlink(self, p, target): + os.symlink(target, p) + + def create_hierarchy(self, p): + os.mkdir(os.path.join(p, 'dirA')) + os.mkdir(os.path.join(p, 'dirB')) + os.mkdir(os.path.join(p, 'dirC')) + os.mkdir(os.path.join(p, 'dirC', 'dirD')) + with open(os.path.join(p, 'fileA'), 'wb') as f: + f.write(b"this is file A\n") + with open(os.path.join(p, 'dirB', 'fileB'), 'wb') as f: + f.write(b"this is file B\n") + with open(os.path.join(p, 'dirC', 'fileC'), 'wb') as f: + f.write(b"this is file C\n") + with open(os.path.join(p, 'dirC', 'novel.txt'), 'wb') as f: + f.write(b"this is a novel\n") + with open(os.path.join(p, 'dirC', 'dirD', 'fileD'), 'wb') as f: + f.write(b"this is file D\n") + if self.can_symlink: + # Relative symlinks. + os.symlink('fileA', os.path.join(p, 'linkA')) + os.symlink('non-existing', os.path.join(p, 'brokenLink')) + os.symlink('dirB', + os.path.join(p, 'linkB'), + target_is_directory=True) + os.symlink(os.path.join('..', 'dirB'), + os.path.join(p, 'dirA', 'linkC'), + target_is_directory=True) + # Broken symlink (pointing to itself). + os.symlink('brokenLinkLoop', os.path.join(p, 'brokenLinkLoop')) + + isdir = staticmethod(os.path.isdir) + isfile = staticmethod(os.path.isfile) + islink = staticmethod(os.path.islink) + readlink = staticmethod(os.readlink) + + def readtext(self, p): + with open(p, 'r') as f: + return f.read() + + def readbytes(self, p): + with open(p, 'rb') as f: + return f.read() + + +class LocalPathInfo(pathlib.types.PathInfo): + """ + Simple implementation of PathInfo for a local path + """ + __slots__ = ('_path', '_exists', '_is_dir', '_is_file', '_is_symlink') + + def __init__(self, path): + self._path = str(path) + self._exists = None + self._is_dir = None + self._is_file = None + self._is_symlink = None + + def exists(self, *, follow_symlinks=True): + """Whether this path exists.""" + if not follow_symlinks and self.is_symlink(): + return True + if self._exists is None: + self._exists = os.path.exists(self._path) + return self._exists + + def is_dir(self, *, follow_symlinks=True): + """Whether this path is a directory.""" + if not follow_symlinks and self.is_symlink(): + return False + if self._is_dir is None: + self._is_dir = os.path.isdir(self._path) + return self._is_dir + + def is_file(self, *, follow_symlinks=True): + """Whether this path is a regular file.""" + if not follow_symlinks and self.is_symlink(): + return False + if self._is_file is None: + self._is_file = os.path.isfile(self._path) + return self._is_file + + def is_symlink(self): + """Whether this path is a symbolic link.""" + if self._is_symlink is None: + self._is_symlink = os.path.islink(self._path) + return self._is_symlink + + +class ReadableLocalPath(pathlib.types._ReadablePath, LexicalPath): + """ + Simple implementation of a ReadablePath class for local filesystem paths. + """ + __slots__ = ('info',) + + def __init__(self, *pathsegments): + super().__init__(*pathsegments) + self.info = LocalPathInfo(self) + + def __fspath__(self): + return str(self) + + def __open_rb__(self, buffering=-1): + return open(self, 'rb') + + def iterdir(self): + return (self / name for name in os.listdir(self)) + + def readlink(self): + return self.with_segments(os.readlink(self)) diff --git a/Lib/test/test_pathlib/support/zip_path.py b/Lib/test/test_pathlib/support/zip_path.py new file mode 100644 index 00000000000000..ab6a929fc4a504 --- /dev/null +++ b/Lib/test/test_pathlib/support/zip_path.py @@ -0,0 +1,278 @@ +""" +Implementation of ReadablePath for zip file members, for use in pathlib tests. + +ZipPathGround is also defined here. It helps establish the "ground truth" +about zip file members in tests. +""" + +import errno +import io +import pathlib.types +import posixpath +import stat +import zipfile +from stat import S_IFMT, S_ISDIR, S_ISREG, S_ISLNK + + +class ZipPathGround: + can_symlink = True + + def __init__(self, path_cls): + self.path_cls = path_cls + + def setup(self, local_suffix=""): + return self.path_cls(zip_file=zipfile.ZipFile(io.BytesIO(), "w")) + + def teardown(self, root): + root.zip_file.close() + + def create_file(self, path, data=b''): + path.zip_file.writestr(str(path), data) + + def create_dir(self, path): + path.zip_file.mkdir(str(path)) + + def create_symlink(self, path, target): + zip_info = zipfile.ZipInfo(str(path)) + zip_info.external_attr = stat.S_IFLNK << 16 + path.zip_file.writestr(zip_info, target.encode()) + + def create_hierarchy(self, p): + # Add regular files + self.create_file(p.joinpath('fileA'), b'this is file A\n') + self.create_file(p.joinpath('dirB/fileB'), b'this is file B\n') + self.create_file(p.joinpath('dirC/fileC'), b'this is file C\n') + self.create_file(p.joinpath('dirC/dirD/fileD'), b'this is file D\n') + self.create_file(p.joinpath('dirC/novel.txt'), b'this is a novel\n') + # Add symlinks + self.create_symlink(p.joinpath('linkA'), 'fileA') + self.create_symlink(p.joinpath('linkB'), 'dirB') + self.create_symlink(p.joinpath('dirA/linkC'), '../dirB') + self.create_symlink(p.joinpath('brokenLink'), 'non-existing') + self.create_symlink(p.joinpath('brokenLinkLoop'), 'brokenLinkLoop') + + def readtext(self, p): + with p.zip_file.open(str(p), 'r') as f: + f = io.TextIOWrapper(f) + return f.read() + + def readbytes(self, p): + with p.zip_file.open(str(p), 'r') as f: + return f.read() + + readlink = readtext + + def isdir(self, p): + path_str = str(p) + "/" + return path_str in p.zip_file.NameToInfo + + def isfile(self, p): + info = p.zip_file.NameToInfo.get(str(p)) + if info is None: + return False + return not stat.S_ISLNK(info.external_attr >> 16) + + def islink(self, p): + info = p.zip_file.NameToInfo.get(str(p)) + if info is None: + return False + return stat.S_ISLNK(info.external_attr >> 16) + + +class MissingZipPathInfo: + """ + PathInfo implementation that is used when a zip file member is missing. + """ + __slots__ = () + + def exists(self, follow_symlinks=True): + return False + + def is_dir(self, follow_symlinks=True): + return False + + def is_file(self, follow_symlinks=True): + return False + + def is_symlink(self): + return False + + def resolve(self): + return self + + +missing_zip_path_info = MissingZipPathInfo() + + +class ZipPathInfo: + """ + PathInfo implementation for an existing zip file member. + """ + __slots__ = ('zip_file', 'zip_info', 'parent', 'children') + + def __init__(self, zip_file, parent=None): + self.zip_file = zip_file + self.zip_info = None + self.parent = parent or self + self.children = {} + + def exists(self, follow_symlinks=True): + if follow_symlinks and self.is_symlink(): + return self.resolve().exists() + return True + + def is_dir(self, follow_symlinks=True): + if follow_symlinks and self.is_symlink(): + return self.resolve().is_dir() + elif self.zip_info is None: + return True + elif fmt := S_IFMT(self.zip_info.external_attr >> 16): + return S_ISDIR(fmt) + else: + return self.zip_info.filename.endswith('/') + + def is_file(self, follow_symlinks=True): + if follow_symlinks and self.is_symlink(): + return self.resolve().is_file() + elif self.zip_info is None: + return False + elif fmt := S_IFMT(self.zip_info.external_attr >> 16): + return S_ISREG(fmt) + else: + return not self.zip_info.filename.endswith('/') + + def is_symlink(self): + if self.zip_info is None: + return False + elif fmt := S_IFMT(self.zip_info.external_attr >> 16): + return S_ISLNK(fmt) + else: + return False + + def resolve(self, path=None, create=False, follow_symlinks=True): + """ + Traverse zip hierarchy (parents, children and symlinks) starting + from this PathInfo. This is called from three places: + + - When a zip file member is added to ZipFile.filelist, this method + populates the ZipPathInfo tree (using create=True). + - When ReadableZipPath.info is accessed, this method is finds a + ZipPathInfo entry for the path without resolving any final symlink + (using follow_symlinks=False) + - When ZipPathInfo methods are called with follow_symlinks=True, this + method resolves any symlink in the final path position. + """ + link_count = 0 + stack = path.split('/')[::-1] if path else [] + info = self + while True: + if info.is_symlink() and (follow_symlinks or stack): + link_count += 1 + if link_count >= 40: + return missing_zip_path_info # Symlink loop! + path = info.zip_file.read(info.zip_info).decode() + stack += path.split('/')[::-1] if path else [] + info = info.parent + + if stack: + name = stack.pop() + else: + return info + + if name == '..': + info = info.parent + elif name and name != '.': + if name not in info.children: + if create: + info.children[name] = ZipPathInfo(info.zip_file, info) + else: + return missing_zip_path_info # No such child! + info = info.children[name] + + +class ZipFileList: + """ + `list`-like object that we inject as `ZipFile.filelist`. We maintain a + tree of `ZipPathInfo` objects representing the zip file members. + """ + + __slots__ = ('tree', '_items') + + def __init__(self, zip_file): + self.tree = ZipPathInfo(zip_file) + self._items = [] + for item in zip_file.filelist: + self.append(item) + + def __len__(self): + return len(self._items) + + def __iter__(self): + return iter(self._items) + + def append(self, item): + self._items.append(item) + self.tree.resolve(item.filename, create=True).zip_info = item + + +class ReadableZipPath(pathlib.types._ReadablePath): + """ + Simple implementation of a ReadablePath class for .zip files. + """ + + __slots__ = ('_segments', 'zip_file') + parser = posixpath + + def __init__(self, *pathsegments, zip_file): + self._segments = pathsegments + self.zip_file = zip_file + if not isinstance(zip_file.filelist, ZipFileList): + zip_file.filelist = ZipFileList(zip_file) + + def __hash__(self): + return hash((str(self), self.zip_file)) + + def __eq__(self, other): + if not isinstance(other, ReadableZipPath): + return NotImplemented + return str(self) == str(other) and self.zip_file is other.zip_file + + def __str__(self): + if not self._segments: + return '' + return self.parser.join(*self._segments) + + def __repr__(self): + return f'{type(self).__name__}({str(self)!r}, zip_file={self.zip_file!r})' + + def with_segments(self, *pathsegments): + return type(self)(*pathsegments, zip_file=self.zip_file) + + @property + def info(self): + tree = self.zip_file.filelist.tree + return tree.resolve(str(self), follow_symlinks=False) + + def __open_rb__(self, buffering=-1): + info = self.info.resolve() + if not info.exists(): + raise FileNotFoundError(errno.ENOENT, "File not found", self) + elif info.is_dir(): + raise IsADirectoryError(errno.EISDIR, "Is a directory", self) + return self.zip_file.open(info.zip_info, 'r') + + def iterdir(self): + info = self.info.resolve() + if not info.exists(): + raise FileNotFoundError(errno.ENOENT, "File not found", self) + elif not info.is_dir(): + raise NotADirectoryError(errno.ENOTDIR, "Not a directory", self) + return (self / name for name in info.children) + + def readlink(self): + info = self.info + if not info.exists(): + raise FileNotFoundError(errno.ENOENT, "File not found", self) + elif not info.is_symlink(): + raise OSError(errno.EINVAL, "Not a symlink", self) + return self.with_segments(self.zip_file.read(info.zip_info).decode()) diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index aff155cf1100bb..b9725af0c988f7 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -2429,6 +2429,33 @@ def test_symlink_to_unsupported(self): with self.assertRaises(pathlib.UnsupportedOperation): q.symlink_to(p) + def test_info_exists_caching(self): + p = self.cls(self.base) + q = p / 'myfile' + self.assertFalse(q.info.exists()) + self.assertFalse(q.info.exists(follow_symlinks=False)) + q.write_text('hullo') + self.assertFalse(q.info.exists()) + self.assertFalse(q.info.exists(follow_symlinks=False)) + + def test_info_is_dir_caching(self): + p = self.cls(self.base) + q = p / 'mydir' + self.assertFalse(q.info.is_dir()) + self.assertFalse(q.info.is_dir(follow_symlinks=False)) + q.mkdir() + self.assertFalse(q.info.is_dir()) + self.assertFalse(q.info.is_dir(follow_symlinks=False)) + + def test_info_is_file_caching(self): + p = self.cls(self.base) + q = p / 'myfile' + self.assertFalse(q.info.is_file()) + self.assertFalse(q.info.is_file(follow_symlinks=False)) + q.write_text('hullo') + self.assertFalse(q.info.is_file()) + self.assertFalse(q.info.is_file(follow_symlinks=False)) + @needs_symlinks def test_info_is_symlink_caching(self): p = self.cls(self.base) diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py index a93af961b503a1..02e2a1da7ee7d2 100644 --- a/Lib/test/test_pathlib/test_pathlib_abc.py +++ b/Lib/test/test_pathlib/test_pathlib_abc.py @@ -314,76 +314,6 @@ def assertEqualNormCase(self, path_a, path_b): normcase = self.parser.normcase self.assertEqual(normcase(path_a), normcase(path_b)) - def test_is_readable(self): - p = self.cls(self.base) - self.assertIsInstance(p, _ReadablePath) - - def test_magic_open(self): - p = self.cls(self.base) - with magic_open(p / 'fileA', 'r') as f: - self.assertIsInstance(f, io.TextIOBase) - self.assertEqual(f.read(), "this is file A\n") - with magic_open(p / 'fileA', 'rb') as f: - self.assertIsInstance(f, io.BufferedIOBase) - self.assertEqual(f.read().strip(), b"this is file A") - - def test_iterdir(self): - P = self.cls - p = P(self.base) - it = p.iterdir() - paths = set(it) - expected = ['dirA', 'dirB', 'dirC', 'dirE', 'fileA'] - if self.can_symlink: - expected += ['linkA', 'linkB', 'brokenLink', 'brokenLinkLoop'] - self.assertEqual(paths, { P(self.base, q) for q in expected }) - - def test_iterdir_nodir(self): - # __iter__ on something that is not a directory. - p = self.cls(self.base, 'fileA') - with self.assertRaises(OSError) as cm: - p.iterdir() - # ENOENT or EINVAL under Windows, ENOTDIR otherwise - # (see issue #12802). - self.assertIn(cm.exception.errno, (errno.ENOTDIR, - errno.ENOENT, errno.EINVAL)) - - def test_iterdir_info(self): - p = self.cls(self.base) - for child in p.iterdir(): - self.assertIsInstance(child.info, PathInfo) - self.assertTrue(child.info.exists(follow_symlinks=False)) - - def test_glob_common(self): - def _check(glob, expected): - self.assertEqual(set(glob), { P(self.base, q) for q in expected }) - P = self.cls - p = P(self.base) - it = p.glob("fileA") - self.assertIsInstance(it, collections.abc.Iterator) - _check(it, ["fileA"]) - _check(p.glob("fileB"), []) - _check(p.glob("dir*/file*"), ["dirB/fileB", "dirC/fileC"]) - if not self.can_symlink: - _check(p.glob("*A"), ['dirA', 'fileA']) - else: - _check(p.glob("*A"), ['dirA', 'fileA', 'linkA']) - if not self.can_symlink: - _check(p.glob("*B/*"), ['dirB/fileB']) - else: - _check(p.glob("*B/*"), ['dirB/fileB', 'dirB/linkD', - 'linkB/fileB', 'linkB/linkD']) - if not self.can_symlink: - _check(p.glob("*/fileB"), ['dirB/fileB']) - else: - _check(p.glob("*/fileB"), ['dirB/fileB', 'linkB/fileB']) - if self.can_symlink: - _check(p.glob("brokenLink"), ['brokenLink']) - - if not self.can_symlink: - _check(p.glob("*/"), ["dirA/", "dirB/", "dirC/", "dirE/"]) - else: - _check(p.glob("*/"), ["dirA/", "dirB/", "dirC/", "dirE/", "linkB/"]) - @needs_posix def test_glob_posix(self): P = self.cls @@ -402,123 +332,6 @@ def test_glob_windows(self): self.assertEqual(set(p.glob("*a\\")), { P(self.base, "dirA/") }) self.assertEqual(set(p.glob("F*a")), { P(self.base, "fileA") }) - def test_glob_empty_pattern(self): - P = self.cls - p = P(self.base) - self.assertEqual(list(p.glob("")), [p.joinpath("")]) - - def test_info_exists(self): - p = self.cls(self.base) - self.assertTrue(p.info.exists()) - self.assertTrue((p / 'dirA').info.exists()) - self.assertTrue((p / 'dirA').info.exists(follow_symlinks=False)) - self.assertTrue((p / 'fileA').info.exists()) - self.assertTrue((p / 'fileA').info.exists(follow_symlinks=False)) - self.assertFalse((p / 'non-existing').info.exists()) - self.assertFalse((p / 'non-existing').info.exists(follow_symlinks=False)) - if self.can_symlink: - self.assertTrue((p / 'linkA').info.exists()) - self.assertTrue((p / 'linkA').info.exists(follow_symlinks=False)) - self.assertTrue((p / 'linkB').info.exists()) - self.assertTrue((p / 'linkB').info.exists(follow_symlinks=True)) - self.assertFalse((p / 'brokenLink').info.exists()) - self.assertTrue((p / 'brokenLink').info.exists(follow_symlinks=False)) - self.assertFalse((p / 'brokenLinkLoop').info.exists()) - self.assertTrue((p / 'brokenLinkLoop').info.exists(follow_symlinks=False)) - self.assertFalse((p / 'fileA\udfff').info.exists()) - self.assertFalse((p / 'fileA\udfff').info.exists(follow_symlinks=False)) - self.assertFalse((p / 'fileA\x00').info.exists()) - self.assertFalse((p / 'fileA\x00').info.exists(follow_symlinks=False)) - - def test_info_exists_caching(self): - p = self.cls(self.base) - q = p / 'myfile' - self.assertFalse(q.info.exists()) - self.assertFalse(q.info.exists(follow_symlinks=False)) - if isinstance(self.cls, _WritablePath): - q.write_text('hullo') - self.assertFalse(q.info.exists()) - self.assertFalse(q.info.exists(follow_symlinks=False)) - - def test_info_is_dir(self): - p = self.cls(self.base) - self.assertTrue((p / 'dirA').info.is_dir()) - self.assertTrue((p / 'dirA').info.is_dir(follow_symlinks=False)) - self.assertFalse((p / 'fileA').info.is_dir()) - self.assertFalse((p / 'fileA').info.is_dir(follow_symlinks=False)) - self.assertFalse((p / 'non-existing').info.is_dir()) - self.assertFalse((p / 'non-existing').info.is_dir(follow_symlinks=False)) - if self.can_symlink: - self.assertFalse((p / 'linkA').info.is_dir()) - self.assertFalse((p / 'linkA').info.is_dir(follow_symlinks=False)) - self.assertTrue((p / 'linkB').info.is_dir()) - self.assertFalse((p / 'linkB').info.is_dir(follow_symlinks=False)) - self.assertFalse((p / 'brokenLink').info.is_dir()) - self.assertFalse((p / 'brokenLink').info.is_dir(follow_symlinks=False)) - self.assertFalse((p / 'brokenLinkLoop').info.is_dir()) - self.assertFalse((p / 'brokenLinkLoop').info.is_dir(follow_symlinks=False)) - self.assertFalse((p / 'dirA\udfff').info.is_dir()) - self.assertFalse((p / 'dirA\udfff').info.is_dir(follow_symlinks=False)) - self.assertFalse((p / 'dirA\x00').info.is_dir()) - self.assertFalse((p / 'dirA\x00').info.is_dir(follow_symlinks=False)) - - def test_info_is_dir_caching(self): - p = self.cls(self.base) - q = p / 'mydir' - self.assertFalse(q.info.is_dir()) - self.assertFalse(q.info.is_dir(follow_symlinks=False)) - if isinstance(self.cls, _WritablePath): - q.mkdir() - self.assertFalse(q.info.is_dir()) - self.assertFalse(q.info.is_dir(follow_symlinks=False)) - - def test_info_is_file(self): - p = self.cls(self.base) - self.assertTrue((p / 'fileA').info.is_file()) - self.assertTrue((p / 'fileA').info.is_file(follow_symlinks=False)) - self.assertFalse((p / 'dirA').info.is_file()) - self.assertFalse((p / 'dirA').info.is_file(follow_symlinks=False)) - self.assertFalse((p / 'non-existing').info.is_file()) - self.assertFalse((p / 'non-existing').info.is_file(follow_symlinks=False)) - if self.can_symlink: - self.assertTrue((p / 'linkA').info.is_file()) - self.assertFalse((p / 'linkA').info.is_file(follow_symlinks=False)) - self.assertFalse((p / 'linkB').info.is_file()) - self.assertFalse((p / 'linkB').info.is_file(follow_symlinks=False)) - self.assertFalse((p / 'brokenLink').info.is_file()) - self.assertFalse((p / 'brokenLink').info.is_file(follow_symlinks=False)) - self.assertFalse((p / 'brokenLinkLoop').info.is_file()) - self.assertFalse((p / 'brokenLinkLoop').info.is_file(follow_symlinks=False)) - self.assertFalse((p / 'fileA\udfff').info.is_file()) - self.assertFalse((p / 'fileA\udfff').info.is_file(follow_symlinks=False)) - self.assertFalse((p / 'fileA\x00').info.is_file()) - self.assertFalse((p / 'fileA\x00').info.is_file(follow_symlinks=False)) - - def test_info_is_file_caching(self): - p = self.cls(self.base) - q = p / 'myfile' - self.assertFalse(q.info.is_file()) - self.assertFalse(q.info.is_file(follow_symlinks=False)) - if isinstance(self.cls, _WritablePath): - q.write_text('hullo') - self.assertFalse(q.info.is_file()) - self.assertFalse(q.info.is_file(follow_symlinks=False)) - - def test_info_is_symlink(self): - p = self.cls(self.base) - self.assertFalse((p / 'fileA').info.is_symlink()) - self.assertFalse((p / 'dirA').info.is_symlink()) - self.assertFalse((p / 'non-existing').info.is_symlink()) - if self.can_symlink: - self.assertTrue((p / 'linkA').info.is_symlink()) - self.assertTrue((p / 'linkB').info.is_symlink()) - self.assertTrue((p / 'brokenLink').info.is_symlink()) - self.assertFalse((p / 'linkA\udfff').info.is_symlink()) - self.assertFalse((p / 'linkA\x00').info.is_symlink()) - self.assertTrue((p / 'brokenLinkLoop').info.is_symlink()) - self.assertFalse((p / 'fileA\udfff').info.is_symlink()) - self.assertFalse((p / 'fileA\x00').info.is_symlink()) - class WritablePathTest(JoinablePathTest): cls = DummyWritablePath @@ -553,21 +366,6 @@ def test_read_write_text(self): self.assertRaises(TypeError, (p / 'fileA').write_text, b'somebytes') self.assertEqual((p / 'fileA').read_text(encoding='latin-1'), 'äbcdefg') - def test_read_text_with_newlines(self): - p = self.cls(self.base) - # Check that `\n` character change nothing - (p / 'fileA').write_bytes(b'abcde\r\nfghlk\n\rmnopq') - self.assertEqual((p / 'fileA').read_text(newline='\n'), - 'abcde\r\nfghlk\n\rmnopq') - # Check that `\r` character replaces `\n` - (p / 'fileA').write_bytes(b'abcde\r\nfghlk\n\rmnopq') - self.assertEqual((p / 'fileA').read_text(newline='\r'), - 'abcde\r\nfghlk\n\rmnopq') - # Check that `\r\n` character replaces `\n` - (p / 'fileA').write_bytes(b'abcde\r\nfghlk\n\rmnopq') - self.assertEqual((p / 'fileA').read_text(newline='\r\n'), - 'abcde\r\nfghlk\n\rmnopq') - def test_write_text_with_newlines(self): p = self.cls(self.base) # Check that `\n` character change nothing @@ -763,72 +561,6 @@ def tearDown(self): cls._files.clear() cls._directories.clear() - def test_walk_topdown(self): - walker = self.walk_path.walk() - entry = next(walker) - entry[1].sort() # Ensure we visit SUB1 before SUB2 - self.assertEqual(entry, (self.walk_path, ["SUB1", "SUB2"], ["tmp1"])) - entry = next(walker) - self.assertEqual(entry, (self.sub1_path, ["SUB11"], ["tmp2"])) - entry = next(walker) - self.assertEqual(entry, (self.sub11_path, [], [])) - entry = next(walker) - entry[1].sort() - entry[2].sort() - self.assertEqual(entry, self.sub2_tree) - with self.assertRaises(StopIteration): - next(walker) - - def test_walk_prune(self): - # Prune the search. - all = [] - for root, dirs, files in self.walk_path.walk(): - all.append((root, dirs, files)) - if 'SUB1' in dirs: - # Note that this also mutates the dirs we appended to all! - dirs.remove('SUB1') - - self.assertEqual(len(all), 2) - self.assertEqual(all[0], (self.walk_path, ["SUB2"], ["tmp1"])) - - all[1][-1].sort() - all[1][1].sort() - self.assertEqual(all[1], self.sub2_tree) - - def test_walk_bottom_up(self): - seen_testfn = seen_sub1 = seen_sub11 = seen_sub2 = False - for path, dirnames, filenames in self.walk_path.walk(top_down=False): - if path == self.walk_path: - self.assertFalse(seen_testfn) - self.assertTrue(seen_sub1) - self.assertTrue(seen_sub2) - self.assertEqual(sorted(dirnames), ["SUB1", "SUB2"]) - self.assertEqual(filenames, ["tmp1"]) - seen_testfn = True - elif path == self.sub1_path: - self.assertFalse(seen_testfn) - self.assertFalse(seen_sub1) - self.assertTrue(seen_sub11) - self.assertEqual(dirnames, ["SUB11"]) - self.assertEqual(filenames, ["tmp2"]) - seen_sub1 = True - elif path == self.sub11_path: - self.assertFalse(seen_sub1) - self.assertFalse(seen_sub11) - self.assertEqual(dirnames, []) - self.assertEqual(filenames, []) - seen_sub11 = True - elif path == self.sub2_path: - self.assertFalse(seen_testfn) - self.assertFalse(seen_sub2) - self.assertEqual(sorted(dirnames), sorted(self.sub2_tree[1])) - self.assertEqual(sorted(filenames), sorted(self.sub2_tree[2])) - seen_sub2 = True - else: - raise AssertionError(f"Unexpected path: {path}") - self.assertTrue(seen_testfn) - - if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_pathlib/test_read.py b/Lib/test/test_pathlib/test_read.py new file mode 100644 index 00000000000000..49015dac3b3998 --- /dev/null +++ b/Lib/test/test_pathlib/test_read.py @@ -0,0 +1,309 @@ +""" +Tests for pathlib.types._ReadablePath +""" + +import collections.abc +import io +import unittest + +from pathlib import Path +from pathlib.types import PathInfo, _ReadablePath +from pathlib._os import magic_open + +from test.test_pathlib.support.local_path import ReadableLocalPath, LocalPathGround +from test.test_pathlib.support.zip_path import ReadableZipPath, ZipPathGround + + +class ReadTestBase: + def setUp(self): + self.root = self.ground.setup() + self.ground.create_hierarchy(self.root) + + def tearDown(self): + self.ground.teardown(self.root) + + def test_is_readable(self): + self.assertIsInstance(self.root, _ReadablePath) + + def test_open_r(self): + p = self.root / 'fileA' + with magic_open(p, 'r') as f: + self.assertIsInstance(f, io.TextIOBase) + self.assertEqual(f.read(), 'this is file A\n') + + def test_open_rb(self): + p = self.root / 'fileA' + with magic_open(p, 'rb') as f: + self.assertEqual(f.read(), b'this is file A\n') + + def test_read_bytes(self): + p = self.root / 'fileA' + self.assertEqual(p.read_bytes(), b'this is file A\n') + + def test_read_text(self): + p = self.root / 'fileA' + self.assertEqual(p.read_text(), 'this is file A\n') + q = self.root / 'abc' + self.ground.create_file(q, b'\xe4bcdefg') + self.assertEqual(q.read_text(encoding='latin-1'), 'äbcdefg') + self.assertEqual(q.read_text(encoding='utf-8', errors='ignore'), 'bcdefg') + + def test_read_text_with_newlines(self): + p = self.root / 'abc' + self.ground.create_file(p, b'abcde\r\nfghlk\n\rmnopq') + # Check that `\n` character change nothing + self.assertEqual(p.read_text(newline='\n'), 'abcde\r\nfghlk\n\rmnopq') + # Check that `\r` character replaces `\n` + self.assertEqual(p.read_text(newline='\r'), 'abcde\r\nfghlk\n\rmnopq') + # Check that `\r\n` character replaces `\n` + self.assertEqual(p.read_text(newline='\r\n'), 'abcde\r\nfghlk\n\rmnopq') + + def test_iterdir(self): + expected = ['dirA', 'dirB', 'dirC', 'fileA'] + if self.ground.can_symlink: + expected += ['linkA', 'linkB', 'brokenLink', 'brokenLinkLoop'] + expected = {self.root.joinpath(name) for name in expected} + actual = set(self.root.iterdir()) + self.assertEqual(actual, expected) + + def test_iterdir_nodir(self): + p = self.root / 'fileA' + self.assertRaises(OSError, p.iterdir) + + def test_iterdir_info(self): + for child in self.root.iterdir(): + self.assertIsInstance(child.info, PathInfo) + self.assertTrue(child.info.exists(follow_symlinks=False)) + + def test_glob(self): + if not self.ground.can_symlink: + self.skipTest("requires symlinks") + + p = self.root + sep = self.root.parser.sep + altsep = self.root.parser.altsep + def check(pattern, expected): + if altsep: + expected = {name.replace(altsep, sep) for name in expected} + expected = {p.joinpath(name) for name in expected} + actual = set(p.glob(pattern, recurse_symlinks=True)) + self.assertEqual(actual, expected) + + it = p.glob("fileA") + self.assertIsInstance(it, collections.abc.Iterator) + self.assertEqual(list(it), [p.joinpath("fileA")]) + check("*A", ["dirA", "fileA", "linkA"]) + check("*A", ['dirA', 'fileA', 'linkA']) + check("*B/*", ["dirB/fileB", "linkB/fileB"]) + check("*B/*", ['dirB/fileB', 'linkB/fileB']) + check("brokenLink", ['brokenLink']) + check("brokenLinkLoop", ['brokenLinkLoop']) + check("**/", ["", "dirA/", "dirA/linkC/", "dirB/", "dirC/", "dirC/dirD/", "linkB/"]) + check("**/*/", ["dirA/", "dirA/linkC/", "dirB/", "dirC/", "dirC/dirD/", "linkB/"]) + check("*/", ["dirA/", "dirB/", "dirC/", "linkB/"]) + check("*/dirD/**/", ["dirC/dirD/"]) + check("*/dirD/**", ["dirC/dirD/", "dirC/dirD/fileD"]) + check("dir*/**", ["dirA/", "dirA/linkC", "dirA/linkC/fileB", "dirB/", "dirB/fileB", "dirC/", + "dirC/fileC", "dirC/dirD", "dirC/dirD/fileD", "dirC/novel.txt"]) + check("dir*/**/", ["dirA/", "dirA/linkC/", "dirB/", "dirC/", "dirC/dirD/"]) + check("dir*/**/..", ["dirA/..", "dirA/linkC/..", "dirB/..", "dirC/..", "dirC/dirD/.."]) + check("dir*/*/**", ["dirA/linkC/", "dirA/linkC/fileB", "dirC/dirD/", "dirC/dirD/fileD"]) + check("dir*/*/**/", ["dirA/linkC/", "dirC/dirD/"]) + check("dir*/*/**/..", ["dirA/linkC/..", "dirC/dirD/.."]) + check("dir*/*/..", ["dirC/dirD/..", "dirA/linkC/.."]) + check("dir*/*/../dirD/**/", ["dirC/dirD/../dirD/"]) + check("dir*/**/fileC", ["dirC/fileC"]) + check("dir*/file*", ["dirB/fileB", "dirC/fileC"]) + check("**/*/fileA", []) + check("fileB", []) + check("**/*/fileB", ["dirB/fileB", "dirA/linkC/fileB", "linkB/fileB"]) + check("**/fileB", ["dirB/fileB", "dirA/linkC/fileB", "linkB/fileB"]) + check("*/fileB", ["dirB/fileB", "linkB/fileB"]) + check("*/fileB", ['dirB/fileB', 'linkB/fileB']) + check("**/file*", + ["fileA", "dirA/linkC/fileB", "dirB/fileB", "dirC/fileC", "dirC/dirD/fileD", + "linkB/fileB"]) + + def test_walk_top_down(self): + it = self.root.walk() + + path, dirnames, filenames = next(it) + dirnames.sort() + filenames.sort() + self.assertEqual(path, self.root) + self.assertEqual(dirnames, ['dirA', 'dirB', 'dirC']) + self.assertEqual(filenames, ['brokenLink', 'brokenLinkLoop', 'fileA', 'linkA', 'linkB'] + if self.ground.can_symlink else ['fileA']) + + path, dirnames, filenames = next(it) + self.assertEqual(path, self.root / 'dirA') + self.assertEqual(dirnames, []) + self.assertEqual(filenames, ['linkC'] if self.ground.can_symlink else []) + + path, dirnames, filenames = next(it) + self.assertEqual(path, self.root / 'dirB') + self.assertEqual(dirnames, []) + self.assertEqual(filenames, ['fileB']) + + path, dirnames, filenames = next(it) + filenames.sort() + self.assertEqual(path, self.root / 'dirC') + self.assertEqual(dirnames, ['dirD']) + self.assertEqual(filenames, ['fileC', 'novel.txt']) + + path, dirnames, filenames = next(it) + self.assertEqual(path, self.root / 'dirC' / 'dirD') + self.assertEqual(dirnames, []) + self.assertEqual(filenames, ['fileD']) + + self.assertRaises(StopIteration, next, it) + + def test_walk_prune(self): + expected = {self.root, self.root / 'dirA', self.root / 'dirC', self.root / 'dirC' / 'dirD'} + actual = set() + for path, dirnames, filenames in self.root.walk(): + actual.add(path) + if path == self.root: + dirnames.remove('dirB') + self.assertEqual(actual, expected) + + def test_walk_bottom_up(self): + seen_root = seen_dira = seen_dirb = seen_dirc = seen_dird = False + for path, dirnames, filenames in self.root.walk(top_down=False): + if path == self.root: + self.assertFalse(seen_root) + self.assertTrue(seen_dira) + self.assertTrue(seen_dirb) + self.assertTrue(seen_dirc) + self.assertEqual(sorted(dirnames), ['dirA', 'dirB', 'dirC']) + self.assertEqual(sorted(filenames), + ['brokenLink', 'brokenLinkLoop', 'fileA', 'linkA', 'linkB'] + if self.ground.can_symlink else ['fileA']) + seen_root = True + elif path == self.root / 'dirA': + self.assertFalse(seen_root) + self.assertFalse(seen_dira) + self.assertEqual(dirnames, []) + self.assertEqual(filenames, ['linkC'] if self.ground.can_symlink else []) + seen_dira = True + elif path == self.root / 'dirB': + self.assertFalse(seen_root) + self.assertFalse(seen_dirb) + self.assertEqual(dirnames, []) + self.assertEqual(filenames, ['fileB']) + seen_dirb = True + elif path == self.root / 'dirC': + self.assertFalse(seen_root) + self.assertFalse(seen_dirc) + self.assertTrue(seen_dird) + self.assertEqual(dirnames, ['dirD']) + self.assertEqual(sorted(filenames), ['fileC', 'novel.txt']) + seen_dirc = True + elif path == self.root / 'dirC' / 'dirD': + self.assertFalse(seen_root) + self.assertFalse(seen_dirc) + self.assertFalse(seen_dird) + self.assertEqual(dirnames, []) + self.assertEqual(filenames, ['fileD']) + seen_dird = True + else: + raise AssertionError(f"Unexpected path: {path}") + self.assertTrue(seen_root) + + def test_info_exists(self): + p = self.root + self.assertTrue(p.info.exists()) + self.assertTrue((p / 'dirA').info.exists()) + self.assertTrue((p / 'dirA').info.exists(follow_symlinks=False)) + self.assertTrue((p / 'fileA').info.exists()) + self.assertTrue((p / 'fileA').info.exists(follow_symlinks=False)) + self.assertFalse((p / 'non-existing').info.exists()) + self.assertFalse((p / 'non-existing').info.exists(follow_symlinks=False)) + if self.ground.can_symlink: + self.assertTrue((p / 'linkA').info.exists()) + self.assertTrue((p / 'linkA').info.exists(follow_symlinks=False)) + self.assertTrue((p / 'linkB').info.exists()) + self.assertTrue((p / 'linkB').info.exists(follow_symlinks=True)) + self.assertFalse((p / 'brokenLink').info.exists()) + self.assertTrue((p / 'brokenLink').info.exists(follow_symlinks=False)) + self.assertFalse((p / 'brokenLinkLoop').info.exists()) + self.assertTrue((p / 'brokenLinkLoop').info.exists(follow_symlinks=False)) + self.assertFalse((p / 'fileA\udfff').info.exists()) + self.assertFalse((p / 'fileA\udfff').info.exists(follow_symlinks=False)) + self.assertFalse((p / 'fileA\x00').info.exists()) + self.assertFalse((p / 'fileA\x00').info.exists(follow_symlinks=False)) + + def test_info_is_dir(self): + p = self.root + self.assertTrue((p / 'dirA').info.is_dir()) + self.assertTrue((p / 'dirA').info.is_dir(follow_symlinks=False)) + self.assertFalse((p / 'fileA').info.is_dir()) + self.assertFalse((p / 'fileA').info.is_dir(follow_symlinks=False)) + self.assertFalse((p / 'non-existing').info.is_dir()) + self.assertFalse((p / 'non-existing').info.is_dir(follow_symlinks=False)) + if self.ground.can_symlink: + self.assertFalse((p / 'linkA').info.is_dir()) + self.assertFalse((p / 'linkA').info.is_dir(follow_symlinks=False)) + self.assertTrue((p / 'linkB').info.is_dir()) + self.assertFalse((p / 'linkB').info.is_dir(follow_symlinks=False)) + self.assertFalse((p / 'brokenLink').info.is_dir()) + self.assertFalse((p / 'brokenLink').info.is_dir(follow_symlinks=False)) + self.assertFalse((p / 'brokenLinkLoop').info.is_dir()) + self.assertFalse((p / 'brokenLinkLoop').info.is_dir(follow_symlinks=False)) + self.assertFalse((p / 'dirA\udfff').info.is_dir()) + self.assertFalse((p / 'dirA\udfff').info.is_dir(follow_symlinks=False)) + self.assertFalse((p / 'dirA\x00').info.is_dir()) + self.assertFalse((p / 'dirA\x00').info.is_dir(follow_symlinks=False)) + + def test_info_is_file(self): + p = self.root + self.assertTrue((p / 'fileA').info.is_file()) + self.assertTrue((p / 'fileA').info.is_file(follow_symlinks=False)) + self.assertFalse((p / 'dirA').info.is_file()) + self.assertFalse((p / 'dirA').info.is_file(follow_symlinks=False)) + self.assertFalse((p / 'non-existing').info.is_file()) + self.assertFalse((p / 'non-existing').info.is_file(follow_symlinks=False)) + if self.ground.can_symlink: + self.assertTrue((p / 'linkA').info.is_file()) + self.assertFalse((p / 'linkA').info.is_file(follow_symlinks=False)) + self.assertFalse((p / 'linkB').info.is_file()) + self.assertFalse((p / 'linkB').info.is_file(follow_symlinks=False)) + self.assertFalse((p / 'brokenLink').info.is_file()) + self.assertFalse((p / 'brokenLink').info.is_file(follow_symlinks=False)) + self.assertFalse((p / 'brokenLinkLoop').info.is_file()) + self.assertFalse((p / 'brokenLinkLoop').info.is_file(follow_symlinks=False)) + self.assertFalse((p / 'fileA\udfff').info.is_file()) + self.assertFalse((p / 'fileA\udfff').info.is_file(follow_symlinks=False)) + self.assertFalse((p / 'fileA\x00').info.is_file()) + self.assertFalse((p / 'fileA\x00').info.is_file(follow_symlinks=False)) + + def test_info_is_symlink(self): + p = self.root + self.assertFalse((p / 'fileA').info.is_symlink()) + self.assertFalse((p / 'dirA').info.is_symlink()) + self.assertFalse((p / 'non-existing').info.is_symlink()) + if self.ground.can_symlink: + self.assertTrue((p / 'linkA').info.is_symlink()) + self.assertTrue((p / 'linkB').info.is_symlink()) + self.assertTrue((p / 'brokenLink').info.is_symlink()) + self.assertFalse((p / 'linkA\udfff').info.is_symlink()) + self.assertFalse((p / 'linkA\x00').info.is_symlink()) + self.assertTrue((p / 'brokenLinkLoop').info.is_symlink()) + self.assertFalse((p / 'fileA\udfff').info.is_symlink()) + self.assertFalse((p / 'fileA\x00').info.is_symlink()) + + +class ZipPathReadTest(ReadTestBase, unittest.TestCase): + ground = ZipPathGround(ReadableZipPath) + + +class LocalPathReadTest(ReadTestBase, unittest.TestCase): + ground = LocalPathGround(ReadableLocalPath) + + +class PathReadTest(ReadTestBase, unittest.TestCase): + ground = LocalPathGround(Path) + + +if __name__ == "__main__": + unittest.main()