Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e33ba1

Browse files
authored
gh-94169: Remove deprecated io.OpenWrapper (#94170)
Remove io.OpenWrapper and _pyio.OpenWrapper, deprecated in Python3.10: just use :func:`open` instead. The open() (io.open()) functionis a built-in function. Since Python 3.10, _pyio.open() is also astatic method.
1 parent5075e81 commit6e33ba1

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-
ifname=="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-
importwarnings
314-
warnings.warn('OpenWrapper is deprecated, use open instead',
315-
DeprecationWarning,stacklevel=2)
316-
globalOpenWrapper
317-
OpenWrapper=open
318-
returnOpenWrapper
319-
raiseAttributeError(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-
ifname=="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-
importwarnings
68-
warnings.warn('OpenWrapper is deprecated, use open instead',
69-
DeprecationWarning,stacklevel=2)
70-
globalOpenWrapper
71-
OpenWrapper=open
72-
returnOpenWrapper
73-
raiseAttributeError("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-
deftest_openwrapper(self):
4310-
self.assertIs(self.io.OpenWrapper,self.io.open)
4311-
43124304

43134305
classCMiscIOTest(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)

[8]ページ先頭

©2009-2025 Movatter.jp