Skip to content

Commit eeeb7e5

Browse files
authored
Merge branch '3.13' into openssl-35_3.13
2 parents b99f567 + 6ff52cd commit eeeb7e5

45 files changed

Lines changed: 554 additions & 77 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Doc/builtins/functions.rst‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,14 @@ are always available. They are listed here in alphabetical order.
336336
``__debug__`` is true), ``1`` (asserts are removed, ``__debug__`` is false)
337337
or ``2`` (docstrings are removed too).
338338

339-
This function raises :exc:`SyntaxError` or :exc:`ValueError` if the compiled
340-
source is invalid.
339+
This function raises :exc:`SyntaxError` if the compiled source is invalid,
340+
including a *source* containing a null character or that cannot be decoded;
341+
:exc:`ValueError` if *mode* or *flags* is invalid,
342+
or if a string *source* contains surrogate characters;
343+
:exc:`MemoryError` or :exc:`RecursionError` if *source* is too complex
344+
to parse or compile,
345+
for example an expression with many thousands of nested operators;
346+
and :exc:`OverflowError` if *source* is too large.
341347

342348
If you want to parse Python code into its AST representation, see
343349
:func:`ast.parse`.
@@ -369,10 +375,14 @@ are always available. They are listed here in alphabetical order.
369375
Previously, :exc:`TypeError` was raised when null bytes were encountered
370376
in *source*.
371377

372-
.. versionadded:: 3.8
378+
.. versionchanged:: 3.8
373379
``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` can now be passed in flags to enable
374380
support for top-level ``await``, ``async for``, and ``async with``.
375381

382+
.. versionchanged:: 3.12
383+
:exc:`SyntaxError` is raised instead of :exc:`ValueError` when null bytes
384+
are encountered in *source*.
385+
376386

377387
.. class:: complex(number=0, /)
378388
complex(string, /)

‎Doc/library/code.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Interactive Interpreter Objects
9292
*symbol* is ``'single'``. One of several things can happen:
9393

9494
* The input is incorrect; :func:`compile_command` raised an exception
95-
(:exc:`SyntaxError` or :exc:`OverflowError`). A syntax traceback will be
95+
(usually :exc:`SyntaxError`). A syntax traceback will be
9696
printed by calling the :meth:`showsyntaxerror` method. :meth:`runsource`
9797
returns ``False``.
9898

‎Doc/library/ipaddress.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ write code that handles both IP versions correctly. Address objects are
255255

256256
.. attribute:: ipv6_mapped
257257

258-
:class:`IPv4Address` object representing the IPv4-mapped IPv6 address. See :RFC:`4291`.
258+
:class:`IPv6Address` object representing the IPv4-mapped IPv6 address. See :RFC:`4291`.
259259

260260
.. versionadded:: 3.13
261261

‎Lib/_pyrepl/console.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
195195
ast.PyCF_ONLY_AST,
196196
incomplete_input=False,
197197
)
198-
except (SyntaxError, OverflowError, ValueError):
198+
except Exception:
199199
self.showsyntaxerror(filename, source=source)
200200
return False
201201
if tree.body:
@@ -216,7 +216,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
216216
)
217217
self.showsyntaxerror(filename, source=source)
218218
return False
219-
except (OverflowError, ValueError):
219+
except Exception:
220220
self.showsyntaxerror(filename, source=source)
221221
return False
222222

‎Lib/_pyrepl/simple_interact.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _more_lines(console: code.InteractiveConsole, unicodetext: str) -> bool:
8787
src = _strip_final_indent(unicodetext)
8888
try:
8989
code = console.compile(src, "<stdin>", "single")
90-
except (OverflowError, SyntaxError, ValueError):
90+
except Exception:
9191
lines = src.splitlines(keepends=True)
9292
if len(lines) == 1:
9393
return False

‎Lib/code.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def runsource(self, source, filename="<input>", symbol="single"):
4545
One of several things can happen:
4646
4747
1) The input is incorrect; compile_command() raised an
48-
exception (SyntaxError or OverflowError). A syntax traceback
49-
will be printed by calling the showsyntaxerror() method.
48+
exception (usually SyntaxError). A syntax traceback will be
49+
printed by calling the showsyntaxerror() method.
5050
5151
2) The input is incomplete, and more input is required;
5252
compile_command() returned None. Nothing happens.
@@ -63,7 +63,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
6363
"""
6464
try:
6565
code = self.compile(source, filename, symbol)
66-
except (OverflowError, SyntaxError, ValueError):
66+
except Exception:
6767
# Case 1
6868
self.showsyntaxerror(filename, source=source)
6969
return False

‎Lib/idlelib/__main__.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33
44
Run IDLE as python -m idlelib
55
"""
6+
import sys
7+
8+
if not sys.flags.safe_path:
9+
# Remove the current directory, prepended by "python -m", so that
10+
# user files do not shadow IDLE's imports (gh-70331).
11+
del sys.path[0]
12+
613
import idlelib.pyshell
714
idlelib.pyshell.main()

‎Lib/idlelib/colorizer.py‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
DEBUG = False
1010

11+
# Adding a tag to a line takes time proportional to the number of tags
12+
# already in the line, so only the beginning of a line is colorized;
13+
# the rest is usually not visible anyway (gh-103089).
14+
MAX_COLORIZED_LINE = 2000
15+
1116

1217
def any(name, alternates):
1318
"Return a named group pattern matching list of alternates."
@@ -344,16 +349,39 @@ def _add_tags_in_section(self, chars, head):
344349
`chars` is a string with the text to parse and to which
345350
highlighting is to be applied.
346351
347-
`head` is the index in the text widget where the text is found.
352+
`head` is the index in the text widget where the text is found.
348353
"""
349-
for m in self.prog.finditer(chars):
354+
# Positions are relative to the start of the current line, so that
355+
# Tk does not resolve them through the previous lines.
356+
line = int(head.split('.')[0])
357+
line_start = 0 # Offset of the current line in chars.
358+
tags = []
359+
pos = 0
360+
while True:
361+
m = self.prog.search(chars, pos)
362+
if m is None:
363+
break
350364
for name, matched_text in matched_named_groups(m):
351365
a, b = m.span(name)
352-
self._add_tag(a, b, head, name)
366+
tags.append((a - line_start, b - line_start, head, name))
353367
if matched_text in ("def", "class"):
354368
if m1 := self.idprog.match(chars, b):
355369
a, b = m1.span(1)
356-
self._add_tag(a, b, head, "DEFINITION")
370+
tags.append((a - line_start, b - line_start,
371+
head, "DEFINITION"))
372+
pos = m.end()
373+
if '\n' in m[0]:
374+
line += m[0].count('\n')
375+
line_start = m.start() + m[0].rindex('\n') + 1
376+
head = f"{line}.0"
377+
elif pos - line_start >= MAX_COLORIZED_LINE:
378+
# The rest of a long line is not colorized.
379+
pos = chars.find('\n', pos)
380+
if pos < 0:
381+
break
382+
# Adding a tag is faster if there are no tags after it.
383+
for args in reversed(tags):
384+
self._add_tag(*args)
357385

358386
def removecolors(self):
359387
"Remove all colorizing tags."

‎Lib/idlelib/idle.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import os.path
21
import sys
32

3+
if __spec__ is not None and not sys.flags.safe_path:
4+
# Remove the current directory, prepended by "python -m", so that
5+
# user files do not shadow IDLE's imports (gh-70331).
6+
del sys.path[0]
7+
8+
import os.path
9+
410

511
# Enable running IDLE with idlelib in a non-standard location.
612
# This was once used to run development versions of IDLE.

‎Lib/idlelib/idle_test/test_colorizer.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,18 @@ def test_long_multiline_string(self):
565565
e"""
566566
''')
567567
self._assert_highlighting(source, {'STRING': [('1.0', '5.4')]})
568+
source = '"""a\nb""" + str\n'
569+
self._assert_highlighting(source, {'STRING': [('1.0', '2.4')],
570+
'BUILTIN': [('2.7', '2.10')]})
571+
572+
def test_long_line(self):
573+
# gh-103089: only the first MAX_COLORIZED_LINE characters of a line
574+
# are colorized.
575+
n = colorizer.MAX_COLORIZED_LINE
576+
source = f"pass\n{'x' * (n - 3)}'a', 'b'\n'c'\n"
577+
self._assert_highlighting(source, {'KEYWORD': [('1.0', '1.4')],
578+
'STRING': [(f'2.{n-3}', f'2.{n}'),
579+
('3.0', '3.3')]})
568580

569581
@run_in_tk_mainloop(delay=50)
570582
def test_incremental_editing(self):

0 commit comments

Comments
 (0)