diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index ea2834bc761457..a676c5749a5653 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1133,6 +1133,11 @@ Removed (Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley in :issue:`42392`.) +* Remove the undocumented ``io.OpenWrapper`` and ``_pyio.OpenWrapper`` + functions which could be used directly to define a method: + ``staticmethod(open)`` should now be used instead. + (Contributed by Victor Stinner in :issue:`43680`.) + Porting to Python 3.10 ====================== diff --git a/Lib/_pyio.py b/Lib/_pyio.py index ba0b0a29b5013d..af637925555ae2 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -313,19 +313,6 @@ def __get__(self, obj, typ=None): "errors=None, newline=None, closefd=True)\n\n" + open.__doc__) -class OpenWrapper: - """Wrapper for builtins.open - - Trick so that open won't become a bound method when stored - as a class variable (as dbm.dumb does). - - See initstdio() in Python/pylifecycle.c. - """ - __doc__ = DocDescriptor() - - def __new__(cls, *args, **kwargs): - return open(*args, **kwargs) - # In normal operation, both `UnsupportedOperation`s should be bound to the # same object. diff --git a/Lib/io.py b/Lib/io.py index 01f1df80ded297..11b188cb50e02f 100644 --- a/Lib/io.py +++ b/Lib/io.py @@ -56,8 +56,6 @@ BufferedWriter, BufferedRWPair, BufferedRandom, IncrementalNewlineDecoder, text_encoding, TextIOWrapper) -OpenWrapper = _io.open # for compatibility with _pyio - # Pretend this exception was created here. UnsupportedOperation.__module__ = "io" diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 6a9ce39f08eb58..5e82457af4fa3e 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -4574,6 +4574,13 @@ class PySignalsTest(SignalsTest): test_reentrant_write_text = None +class PyioOpenWrapper: + """Wrapper for pyio.open Trick so that open won't become a bound method + when stored as a class variable.""" + def __new__(cls, *args, **kwargs): + return pyio.open(*args, **kwargs) + + def load_tests(*args): tests = (CIOTest, PyIOTest, APIMismatchTest, CBufferedReaderTest, PyBufferedReaderTest, @@ -4599,7 +4606,7 @@ def load_tests(*args): c_io_ns.update((x.__name__, globs["C" + x.__name__]) for x in mocks) py_io_ns.update((x.__name__, globs["Py" + x.__name__]) for x in mocks) # Avoid turning open into a bound method. - py_io_ns["open"] = pyio.OpenWrapper + py_io_ns["open"] = PyioOpenWrapper for test in tests: if test.__name__.startswith("C"): for name, obj in c_io_ns.items(): diff --git a/Misc/NEWS.d/next/Library/2021-03-31-15-08-59.bpo-43680.H_Mx8U.rst b/Misc/NEWS.d/next/Library/2021-03-31-15-08-59.bpo-43680.H_Mx8U.rst new file mode 100644 index 00000000000000..4c83676da4064d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-03-31-15-08-59.bpo-43680.H_Mx8U.rst @@ -0,0 +1,3 @@ +Remove the undocumented ``io.OpenWrapper`` and ``_pyio.OpenWrapper`` +functions which could be used directly to define a method: +``staticmethod(open)`` should now be used instead. diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 8309477806f7a3..14008a89bf6d13 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2213,11 +2213,11 @@ create_stdio(const PyConfig *config, PyObject* io, return NULL; } -/* Set builtins.open to io.OpenWrapper */ +/* Set builtins.open to io.open */ static PyStatus init_set_builtins_open(void) { - PyObject *iomod = NULL, *wrapper; + PyObject *iomod = NULL, *open_func; PyObject *bimod = NULL; PyStatus res = _PyStatus_OK(); @@ -2229,16 +2229,16 @@ init_set_builtins_open(void) goto error; } - if (!(wrapper = PyObject_GetAttrString(iomod, "OpenWrapper"))) { + if (!(open_func = PyObject_GetAttrString(iomod, "open"))) { goto error; } /* Set builtins.open */ - if (PyObject_SetAttrString(bimod, "open", wrapper) == -1) { - Py_DECREF(wrapper); + if (PyObject_SetAttrString(bimod, "open", open_func) == -1) { + Py_DECREF(open_func); goto error; } - Py_DECREF(wrapper); + Py_DECREF(open_func); goto done; error: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy