You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deprecate undocumented io.OpenWrapper and _pyio.OpenWrapper #87846
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](https://github.com/python/cpython/blob/main/Python/pylifecycle.c).
"""
__doc__ = DocDescriptor()
As for dbm.dumb, it was an attempt to make _Database._commit() working at the shutdown stage (it is indirectly called from __del__()). See bpo-723231. Although in Python 2 __builtin__.open != io.open, and in Python 3.0 the code already uses io.open directly.
I afraid that this code is not reliable (and never was reliable), because modules os and io can be cleared before calling it, so os.unlink and io.open would not work. But this is a different issue.
OpenWrapper was added in ce3a72a (bpo-1267) and was only used to set __builtin__.open (I suppose that at thet moment dumbdbm.py still set open as a class attribute).
It is still can be set as a class attribute in user code, so I think that removing OpenWrapper needs a deprecated period.
OpenWrapper was added in ce3a72a (bpo-1267) and was only used to set __builtin__.open
It is useless in CPython, since CPython always use the C implementation of the io module, and in the io module, io.OpenWrapper is just an alias to io.open.
$ python3
Python 3.9.2 (default, Feb 20 2021, 00:00:00)
>>> import io
>>> io.OpenWrapper is io.open
True
(I suppose that at thet moment dumbdbm.py still set open as a class attribute).
I failed to find where in Lib/dbm/dumb.py the open() function is used to define a method. Maybe the code changed since OpenWrapper was added?
At commit ce3a72a, the io module was only implemented in Python (Lib/io.py, _io exist didn't exist). It was reimplemented in C in Python 3.1.
It is still can be set as a class attribute in user code, so I think that removing OpenWrapper needs a deprecated period.
I'm fine with deprecating the function by defining a __getattr__() function in io.py and _pyio.py. But only if it doesn't block the implementation of the PEP-597 ;-) The PEP-597 implementation issue is discussed at: https://bugs.python.org/issue43510#msg389822
changed the title [-]Remove undocumented io.OpenWrapper and _pyio.OpenWrapper[/-][+]Deprecate undocumented io.OpenWrapper and _pyio.OpenWrapper[/+]on Apr 14, 2021
changed the title [-]Remove undocumented io.OpenWrapper and _pyio.OpenWrapper[/-][+]Deprecate undocumented io.OpenWrapper and _pyio.OpenWrapper[/+]on Apr 14, 2021
Activity
vstinner commentedon Mar 31, 2021
The OpenWrapper function of io and _pyio is an undocumented hack allowing to use the builtin open() function as a method:
It is only needed by the _pyio module: the pure Python implementation of the io module:
---
The io module simply uses an alias to open:
---
No wrapper is needed since built-in functions can be used directly as methods. Example:
---
This example works as expected, it displays "3" two times.
I propose to simply remove io.OpenWrapper and force developers to explicitly use staticmethod:
io.OpenWrapper is not documented.
I don't understand the remark about dbm.dumb: I fail to see where the built-in open() function is used as a method.
vstinner commentedon Mar 31, 2021
I also opened a discussion on python-dev about OpenWrapper and staticmethod:
https://mail.python.org/archives/list/python-dev@python.org/thread/QZ7SFW3IW3S2C5RMRJZOOUFSHHUINNME/
serhiy-storchaka commentedon Mar 31, 2021
As for dbm.dumb, it was an attempt to make _Database._commit() working at the shutdown stage (it is indirectly called from __del__()). See bpo-723231. Although in Python 2 __builtin__.open != io.open, and in Python 3.0 the code already uses io.open directly.
I afraid that this code is not reliable (and never was reliable), because modules os and io can be cleared before calling it, so os.unlink and io.open would not work. But this is a different issue.
serhiy-storchaka commentedon Mar 31, 2021
OpenWrapper was added in ce3a72a (bpo-1267) and was only used to set __builtin__.open (I suppose that at thet moment dumbdbm.py still set open as a class attribute).
It is still can be set as a class attribute in user code, so I think that removing OpenWrapper needs a deprecated period.
vstinner commentedon Mar 31, 2021
It is useless in CPython, since CPython always use the C implementation of the io module, and in the io module, io.OpenWrapper is just an alias to io.open.
I failed to find where in Lib/dbm/dumb.py the open() function is used to define a method. Maybe the code changed since OpenWrapper was added?
At commit ce3a72a, the io module was only implemented in Python (Lib/io.py, _io exist didn't exist). It was reimplemented in C in Python 3.1.
vstinner commentedon Mar 31, 2021
I'm fine with deprecating the function by defining a __getattr__() function in io.py and _pyio.py. But only if it doesn't block the implementation of the PEP-597 ;-) The PEP-597 implementation issue is discussed at:
https://bugs.python.org/issue43510#msg389822
vstinner commentedon Apr 12, 2021
New changeset 77d668b by Victor Stinner in branch 'master':
bpo-43680: _pyio.open() becomes a static method (GH-25354)
77d668b
vstinner commentedon Apr 14, 2021
New changeset 3bc694d by Victor Stinner in branch 'master':
bpo-43680: Deprecate io.OpenWrapper (GH-25357)
3bc694d
[-]Remove undocumented io.OpenWrapper and _pyio.OpenWrapper[/-][+]Deprecate undocumented io.OpenWrapper and _pyio.OpenWrapper[/+][-]Remove undocumented io.OpenWrapper and _pyio.OpenWrapper[/-][+]Deprecate undocumented io.OpenWrapper and _pyio.OpenWrapper[/+][3.11] pythongh-87846: test_io: Ignore OpenWrapper in test___all__
[3.11] pythongh-87846: test_io: Ignore OpenWrapper in test___all__
[3.11] pythongh-87846: test_io: Ignore OpenWrapper in test___all__
[3.11] pythongh-87846: test_io: Ignore OpenWrapper in test___all__
encukou commentedon Nov 6, 2024
This can make
test___all__fail, see #126478.[3.11] gh-87846: test_io: Ignore OpenWrapper in test___all__ (#126478)