Skip to content

Commit 6e33ba1

Browse files
authored
gh-94169: Remove deprecated io.OpenWrapper (#94170)
Remove io.OpenWrapper and _pyio.OpenWrapper, deprecated in Python 3.10: just use :func:`open` instead. The open() (io.open()) function is a built-in function. Since Python 3.10, _pyio.open() is also a static method.
1 parent 5075e81 commit 6e33ba1

File tree

5 files changed

+10
-40
lines changed

5 files changed

+10
-40
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ Removed
208208
(and corresponding ``EXPERIMENTAL_ISOLATED_SUBINTERPRETERS``)
209209
have been removed.
210210

211+
* Remove ``io.OpenWrapper`` and ``_pyio.OpenWrapper``, deprecated in Python
212+
3.10: just use :func:`open` instead. The :func:`open` (:func:`io.open`)
213+
function is a built-in function. Since Python 3.10, :func:`_pyio.open` is
214+
also a static method.
215+
(Contributed by Victor Stinner in :gh:`94169`.)
216+
211217

212218
Porting to Python 3.12
213219
======================

Lib/_pyio.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -303,22 +303,6 @@ def _open_code_with_warning(path):
303303
open_code = _open_code_with_warning
304304

305305

306-
def __getattr__(name):
307-
if name == "OpenWrapper":
308-
# bpo-43680: Until Python 3.9, _pyio.open was not a static method and
309-
# builtins.open was set to OpenWrapper to not become a bound method
310-
# when set to a class variable. _io.open is a built-in function whereas
311-
# _pyio.open is a Python function. In Python 3.10, _pyio.open() is now
312-
# a static method, and builtins.open() is now io.open().
313-
import warnings
314-
warnings.warn('OpenWrapper is deprecated, use open instead',
315-
DeprecationWarning, stacklevel=2)
316-
global OpenWrapper
317-
OpenWrapper = open
318-
return OpenWrapper
319-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
320-
321-
322306
# In normal operation, both `UnsupportedOperation`s should be bound to the
323307
# same object.
324308
try:

Lib/io.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,6 @@
5757
IncrementalNewlineDecoder, text_encoding, TextIOWrapper)
5858

5959

60-
def __getattr__(name):
61-
if name == "OpenWrapper":
62-
# bpo-43680: Until Python 3.9, _pyio.open was not a static method and
63-
# builtins.open was set to OpenWrapper to not become a bound method
64-
# when set to a class variable. _io.open is a built-in function whereas
65-
# _pyio.open is a Python function. In Python 3.10, _pyio.open() is now
66-
# a static method, and builtins.open() is now io.open().
67-
import warnings
68-
warnings.warn('OpenWrapper is deprecated, use open instead',
69-
DeprecationWarning, stacklevel=2)
70-
global OpenWrapper
71-
OpenWrapper = open
72-
return OpenWrapper
73-
raise AttributeError("module {__name__!r} has no attribute {name!r}")
74-
75-
7660
# Pretend this exception was created here.
7761
UnsupportedOperation.__module__ = "io"
7862

Lib/test/test_io.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,14 +4301,6 @@ def test_text_encoding(self):
43014301
proc = assert_python_ok('-X', 'utf8=1', '-c', code)
43024302
self.assertEqual(b"utf-8", proc.out.strip())
43034303

4304-
@support.cpython_only
4305-
# Depending if OpenWrapper was already created or not, the warning is
4306-
# emitted or not. For example, the attribute is already created when this
4307-
# test is run multiple times.
4308-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
4309-
def test_openwrapper(self):
4310-
self.assertIs(self.io.OpenWrapper, self.io.open)
4311-
43124304

43134305
class CMiscIOTest(MiscIOTest):
43144306
io = io
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Remove ``io.OpenWrapper`` and ``_pyio.OpenWrapper``, deprecated in Python
2+
3.10: just use :func:`open` instead. The :func:`open` (:func:`io.open`)
3+
function is a built-in function. Since Python 3.10, :func:`_pyio.open` is
4+
also a static method. Patch by Victor Stinner.

0 commit comments

Comments
 (0)
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