Skip to content

Commit e8f4ce6

Browse files
committed
Merge branch 'main' into virtual-iterators
2 parents 35e389d + 5ea9010 commit e8f4ce6

37 files changed

+508
-348
lines changed

.github/workflows/mypy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- "Lib/_colorize.py"
1212
- "Lib/_pyrepl/**"
1313
- "Lib/test/libregrtest/**"
14+
- "Lib/tomllib/**"
1415
- "Misc/mypy/**"
1516
- "Tools/build/generate_sbom.py"
1617
- "Tools/cases_generator/**"
@@ -44,6 +45,7 @@ jobs:
4445
target: [
4546
"Lib/_pyrepl",
4647
"Lib/test/libregrtest",
48+
"Lib/tomllib",
4749
"Tools/build",
4850
"Tools/cases_generator",
4951
"Tools/clinic",

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Tools/unicode/data/
143143
/profile-clean-stamp
144144
/profile-run-stamp
145145
/profile-bolt-stamp
146+
/profile-gen-stamp
146147
/pybuilddir.txt
147148
/pyconfig.h
148149
/python-config

Doc/deprecations/pending-removal-in-future.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ although there is currently no date scheduled for their removal.
4747
:data:`calendar.FEBRUARY`.
4848
(Contributed by Prince Roshan in :gh:`103636`.)
4949

50+
* :mod:`codecs`: use :func:`open` instead of :func:`codecs.open`. (:gh:`133038`)
51+
5052
* :attr:`codeobject.co_lnotab`: use the :meth:`codeobject.co_lines` method
5153
instead.
5254

Doc/library/codecs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ wider range of codecs when working with binary files:
208208
.. versionchanged:: 3.11
209209
The ``'U'`` mode has been removed.
210210

211+
.. deprecated:: next
212+
213+
:func:`codecs.open` has been superseded by :func:`open`.
214+
211215

212216
.. function:: EncodedFile(file, data_encoding, file_encoding=None, errors='strict')
213217

Doc/whatsnew/3.14.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,10 @@ Deprecated
15971597
as a single positional argument.
15981598
(Contributed by Serhiy Storchaka in :gh:`109218`.)
15991599

1600+
* :mod:`codecs`:
1601+
:func:`codecs.open` is now deprecated. Use :func:`open` instead.
1602+
(Contributed by Inada Naoki in :gh:`133036`.)
1603+
16001604
* :mod:`functools`:
16011605
Calling the Python implementation of :func:`functools.reduce` with *function*
16021606
or *sequence* as keyword arguments is now deprecated.
@@ -1642,6 +1646,13 @@ Deprecated
16421646
Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest.
16431647
(Contributed by Bénédikt Tran in :gh:`119698`.)
16441648

1649+
* :mod:`tkinter`:
1650+
The :class:`!tkinter.Variable` methods :meth:`!trace_variable`,
1651+
:meth:`!trace_vdelete` and :meth:`!trace_vinfo` are now deprecated.
1652+
Use :meth:`!trace_add`, :meth:`!trace_remove` and :meth:`!trace_info`
1653+
instead.
1654+
(Contributed by Serhiy Storchaka in :gh:`120220`.)
1655+
16451656
* :mod:`urllib.parse`:
16461657
Accepting objects with false values (like ``0`` and ``[]``) except empty
16471658
strings, byte-like objects and ``None`` in :mod:`urllib.parse` functions

Grammar/python.gram

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ _PyPegen_parse(Parser *p)
7979
# ~
8080
# Commit to the current alternative, even if it fails to parse.
8181
# &&e
82-
# Eager parse e. The parser will not backtrack and will immediately
82+
# Eager parse e. The parser will not backtrack and will immediately
8383
# fail with SyntaxError if e cannot be parsed.
8484
#
8585

@@ -659,7 +659,7 @@ type_alias[stmt_ty]:
659659
# Type parameter declaration
660660
# --------------------------
661661

662-
type_params[asdl_type_param_seq*]:
662+
type_params[asdl_type_param_seq*]:
663663
| invalid_type_params
664664
| '[' t=type_param_seq ']' {
665665
CHECK_VERSION(asdl_type_param_seq *, 12, "Type parameter lists are", t) }
@@ -1339,13 +1339,13 @@ invalid_group:
13391339
invalid_import:
13401340
| a='import' ','.dotted_name+ 'from' dotted_name {
13411341
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
1342-
| 'import' token=NEWLINE {
1342+
| 'import' token=NEWLINE {
13431343
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
13441344

13451345
invalid_import_from_targets:
13461346
| import_from_as_names ',' NEWLINE {
13471347
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") }
1348-
| token=NEWLINE {
1348+
| token=NEWLINE {
13491349
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
13501350

13511351
invalid_with_stmt:
@@ -1484,5 +1484,5 @@ invalid_factor:
14841484
invalid_type_params:
14851485
| '[' token=']' {
14861486
RAISE_SYNTAX_ERROR_STARTING_FROM(
1487-
token,
1487+
token,
14881488
"Type parameter list cannot be empty")}

InternalDocs/garbage_collector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ used as follows. If the buffer has reached the maximum size, new object
622622
pointers found while following references are pushed to the stack, rather than
623623
put in the buffer. When dequeuing objects from the buffer, we will "prime" the
624624
buffer if the current length drops below the low threshold. Priming means
625-
popping objects from the stack and enqueing them into the buffer. While
625+
popping objects from the stack and enqueuing them into the buffer. While
626626
priming, we will fill it only until the high threshold is reached.
627627

628628
To measure the effectiveness of the buffer, some benchmark programs were run

Lib/_pyio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,8 +2056,7 @@ def __init__(self, buffer, encoding=None, errors=None, newline=None,
20562056
raise ValueError("invalid encoding: %r" % encoding)
20572057

20582058
if not codecs.lookup(encoding)._is_text_encoding:
2059-
msg = ("%r is not a text encoding; "
2060-
"use codecs.open() to handle arbitrary codecs")
2059+
msg = "%r is not a text encoding"
20612060
raise LookupError(msg % encoding)
20622061

20632062
if errors is None:

Lib/codecs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ def __reduce_ex__(self, proto):
884884
### Shortcuts
885885

886886
def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
887-
888887
""" Open an encoded file using the given mode and return
889888
a wrapped version providing transparent encoding/decoding.
890889
@@ -912,8 +911,11 @@ def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
912911
.encoding which allows querying the used encoding. This
913912
attribute is only available if an encoding was specified as
914913
parameter.
915-
916914
"""
915+
import warnings
916+
warnings.warn("codecs.open() is deprecated. Use open() instead.",
917+
DeprecationWarning, stacklevel=2)
918+
917919
if encoding is not None and \
918920
'b' not in mode:
919921
# Force opening of the file in binary mode

Lib/test/test_codecs.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import unittest
88
import encodings
99
from unittest import mock
10+
import warnings
1011

1112
from test import support
1213
from test.support import os_helper
@@ -20,13 +21,12 @@
2021
except ImportError:
2122
_testinternalcapi = None
2223

23-
try:
24-
import ctypes
25-
except ImportError:
26-
ctypes = None
27-
SIZEOF_WCHAR_T = -1
28-
else:
29-
SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar)
24+
25+
def codecs_open_no_warn(*args, **kwargs):
26+
"""Call codecs.open(*args, **kwargs) ignoring DeprecationWarning."""
27+
with warnings.catch_warnings():
28+
warnings.simplefilter("ignore")
29+
return codecs.open(*args, **kwargs)
3030

3131
def coding_checker(self, coder):
3232
def check(input, expect):
@@ -35,13 +35,13 @@ def check(input, expect):
3535

3636
# On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present
3737
def is_code_page_present(cp):
38-
from ctypes import POINTER, WINFUNCTYPE, WinDLL
38+
from ctypes import POINTER, WINFUNCTYPE, WinDLL, Structure
3939
from ctypes.wintypes import BOOL, BYTE, WCHAR, UINT, DWORD
4040

4141
MAX_LEADBYTES = 12 # 5 ranges, 2 bytes ea., 0 term.
4242
MAX_DEFAULTCHAR = 2 # single or double byte
4343
MAX_PATH = 260
44-
class CPINFOEXW(ctypes.Structure):
44+
class CPINFOEXW(Structure):
4545
_fields_ = [("MaxCharSize", UINT),
4646
("DefaultChar", BYTE*MAX_DEFAULTCHAR),
4747
("LeadByte", BYTE*MAX_LEADBYTES),
@@ -719,19 +719,19 @@ def test_bug691291(self):
719719
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
720720
with open(os_helper.TESTFN, 'wb') as fp:
721721
fp.write(s)
722-
with codecs.open(os_helper.TESTFN, 'r',
722+
with codecs_open_no_warn(os_helper.TESTFN, 'r',
723723
encoding=self.encoding) as reader:
724724
self.assertEqual(reader.read(), s1)
725725

726726
def test_invalid_modes(self):
727727
for mode in ('U', 'rU', 'r+U'):
728728
with self.assertRaises(ValueError) as cm:
729-
codecs.open(os_helper.TESTFN, mode, encoding=self.encoding)
729+
codecs_open_no_warn(os_helper.TESTFN, mode, encoding=self.encoding)
730730
self.assertIn('invalid mode', str(cm.exception))
731731

732732
for mode in ('rt', 'wt', 'at', 'r+t'):
733733
with self.assertRaises(ValueError) as cm:
734-
codecs.open(os_helper.TESTFN, mode, encoding=self.encoding)
734+
codecs_open_no_warn(os_helper.TESTFN, mode, encoding=self.encoding)
735735
self.assertIn("can't have text and binary mode at once",
736736
str(cm.exception))
737737

@@ -1844,9 +1844,9 @@ def test_all(self):
18441844
def test_open(self):
18451845
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
18461846
for mode in ('w', 'r', 'r+', 'w+', 'a', 'a+'):
1847-
with self.subTest(mode), \
1848-
codecs.open(os_helper.TESTFN, mode, 'ascii') as file:
1849-
self.assertIsInstance(file, codecs.StreamReaderWriter)
1847+
with self.subTest(mode), self.assertWarns(DeprecationWarning):
1848+
with codecs.open(os_helper.TESTFN, mode, 'ascii') as file:
1849+
self.assertIsInstance(file, codecs.StreamReaderWriter)
18501850

18511851
def test_undefined(self):
18521852
self.assertRaises(UnicodeError, codecs.encode, 'abc', 'undefined')
@@ -1863,7 +1863,7 @@ def test_file_closes_if_lookup_error_raised(self):
18631863
mock_open = mock.mock_open()
18641864
with mock.patch('builtins.open', mock_open) as file:
18651865
with self.assertRaises(LookupError):
1866-
codecs.open(os_helper.TESTFN, 'wt', 'invalid-encoding')
1866+
codecs_open_no_warn(os_helper.TESTFN, 'wt', 'invalid-encoding')
18671867

18681868
file().close.assert_called()
18691869

@@ -2883,7 +2883,7 @@ def test_seek0(self):
28832883
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
28842884
for encoding in tests:
28852885
# Check if the BOM is written only once
2886-
with codecs.open(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2886+
with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
28872887
f.write(data)
28882888
f.write(data)
28892889
f.seek(0)
@@ -2892,7 +2892,7 @@ def test_seek0(self):
28922892
self.assertEqual(f.read(), data * 2)
28932893

28942894
# Check that the BOM is written after a seek(0)
2895-
with codecs.open(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2895+
with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
28962896
f.write(data[0])
28972897
self.assertNotEqual(f.tell(), 0)
28982898
f.seek(0)
@@ -2901,7 +2901,7 @@ def test_seek0(self):
29012901
self.assertEqual(f.read(), data)
29022902

29032903
# (StreamWriter) Check that the BOM is written after a seek(0)
2904-
with codecs.open(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2904+
with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
29052905
f.writer.write(data[0])
29062906
self.assertNotEqual(f.writer.tell(), 0)
29072907
f.writer.seek(0)
@@ -2911,7 +2911,7 @@ def test_seek0(self):
29112911

29122912
# Check that the BOM is not written after a seek() at a position
29132913
# different than the start
2914-
with codecs.open(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2914+
with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
29152915
f.write(data)
29162916
f.seek(f.tell())
29172917
f.write(data)
@@ -2920,7 +2920,7 @@ def test_seek0(self):
29202920

29212921
# (StreamWriter) Check that the BOM is not written after a seek()
29222922
# at a position different than the start
2923-
with codecs.open(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2923+
with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
29242924
f.writer.write(data)
29252925
f.writer.seek(f.writer.tell())
29262926
f.writer.write(data)

0 commit comments

Comments
 (0)