Skip to content

Commit c8a8d32

Browse files
committed
Align io.py more squarely with CPython 3.10
1 parent 34f6d45 commit c8a8d32

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

Lib/io.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,29 @@
5555
open, open_code, BytesIO, StringIO, BufferedReader,
5656
BufferedWriter, BufferedRWPair, BufferedRandom,
5757
# XXX RUSTPYTHON TODO: IncrementalNewlineDecoder
58-
# IncrementalNewlineDecoder, TextIOWrapper)
59-
TextIOWrapper)
58+
# IncrementalNewlineDecoder, text_encoding, TextIOWrapper)
59+
text_encoding, TextIOWrapper)
6060

6161
try:
6262
from _io import FileIO
6363
except ImportError:
6464
pass
6565

66-
OpenWrapper = _io.open # for compatibility with _pyio
66+
def __getattr__(name):
67+
if name == "OpenWrapper":
68+
# bpo-43680: Until Python 3.9, _pyio.open was not a static method and
69+
# builtins.open was set to OpenWrapper to not become a bound method
70+
# when set to a class variable. _io.open is a built-in function whereas
71+
# _pyio.open is a Python function. In Python 3.10, _pyio.open() is now
72+
# a static method, and builtins.open() is now io.open().
73+
import warnings
74+
warnings.warn('OpenWrapper is deprecated, use open instead',
75+
DeprecationWarning, stacklevel=2)
76+
global OpenWrapper
77+
OpenWrapper = open
78+
return OpenWrapper
79+
raise AttributeError(name)
80+
6781

6882
# Pretend this exception was created here.
6983
UnsupportedOperation.__module__ = "io"

0 commit comments

Comments
 (0)