Skip to content

Commit 9fca2f1

Browse files
Merge branch 'main' into main
2 parents 0bdb82d + de70614 commit 9fca2f1

File tree

8 files changed

+100
-7
lines changed

8 files changed

+100
-7
lines changed

Doc/library/multiprocessing.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,12 @@ object -- see :ref:`multiprocessing-managers`.
13691369
A solitary difference from its close analog exists: its ``acquire`` method's
13701370
first argument is named *block*, as is consistent with :meth:`Lock.acquire`.
13711371

1372+
.. method:: locked()
1373+
1374+
Return a boolean indicating whether this object is locked right now.
1375+
1376+
.. versionadded:: 3.14
1377+
13721378
.. note::
13731379
On macOS, this is indistinguishable from :class:`Semaphore` because
13741380
``sem_getvalue()`` is not implemented on that platform.
@@ -1521,6 +1527,12 @@ object -- see :ref:`multiprocessing-managers`.
15211527
A solitary difference from its close analog exists: its ``acquire`` method's
15221528
first argument is named *block*, as is consistent with :meth:`Lock.acquire`.
15231529

1530+
.. method:: locked()
1531+
1532+
Return a boolean indicating whether this object is locked right now.
1533+
1534+
.. versionadded:: 3.14
1535+
15241536
.. note::
15251537

15261538
On macOS, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with

Include/internal/pycore_opcode_metadata.h

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_pyrepl/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ def from_re(cls, m: Match[str], group: int | str) -> Self:
4141

4242
@classmethod
4343
def from_token(cls, token: TI, line_len: list[int]) -> Self:
44+
end_offset = -1
45+
if (token.type in {T.FSTRING_MIDDLE, T.TSTRING_MIDDLE}
46+
and token.string.endswith(("{", "}"))):
47+
# gh-134158: a visible trailing brace comes from a double brace in input
48+
end_offset += 1
49+
4450
return cls(
4551
line_len[token.start[0] - 1] + token.start[1],
46-
line_len[token.end[0] - 1] + token.end[1] - 1,
52+
line_len[token.end[0] - 1] + token.end[1] + end_offset,
4753
)
4854

4955

Lib/pydoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ def intro(self):
21102110
self.output.write(_introdoc())
21112111

21122112
def list(self, items, columns=4, width=80):
2113-
items = list(sorted(items))
2113+
items = sorted(items)
21142114
colw = width // columns
21152115
rows = (len(items) + columns - 1) // columns
21162116
for row in range(rows):
@@ -2142,7 +2142,7 @@ def listtopics(self):
21422142
Here is a list of available topics. Enter any topic name to get more help.
21432143
21442144
''')
2145-
self.list(self.topics.keys())
2145+
self.list(self.topics.keys(), columns=3)
21462146

21472147
def showtopic(self, topic, more_xrefs=''):
21482148
try:

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,11 +1055,15 @@ def test_parse(self):
10551055
self.assertEqual(actual, parsed)
10561056
# The parser should not get tripped up by any
10571057
# other preceding statements
1058-
code = f'import xyz\n{code}'
1059-
with self.subTest(code=code):
1058+
_code = f'import xyz\n{code}'
1059+
parser = ImportParser(_code)
1060+
actual = parser.parse()
1061+
with self.subTest(code=_code):
10601062
self.assertEqual(actual, parsed)
1061-
code = f'import xyz;{code}'
1062-
with self.subTest(code=code):
1063+
_code = f'import xyz;{code}'
1064+
parser = ImportParser(_code)
1065+
actual = parser.parse()
1066+
with self.subTest(code=_code):
10631067
self.assertEqual(actual, parsed)
10641068

10651069
def test_parse_error(self):

Lib/test/test_pyrepl/test_reader.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,37 @@ def unfinished_function():
517517
self.assert_screen_equal(reader, code, clean=True)
518518
self.assert_screen_equal(reader, expected)
519519

520+
def test_syntax_highlighting_literal_brace_in_fstring_or_tstring(self):
521+
code = dedent(
522+
"""\
523+
f"{{"
524+
f"}}"
525+
f"a{{b"
526+
f"a}}b"
527+
f"a{{b}}c"
528+
t"a{{b}}c"
529+
f"{{{0}}}"
530+
f"{ {0} }"
531+
"""
532+
)
533+
expected = dedent(
534+
"""\
535+
{s}f"{z}{s}<<{z}{s}"{z}
536+
{s}f"{z}{s}>>{z}{s}"{z}
537+
{s}f"{z}{s}a<<{z}{s}b{z}{s}"{z}
538+
{s}f"{z}{s}a>>{z}{s}b{z}{s}"{z}
539+
{s}f"{z}{s}a<<{z}{s}b>>{z}{s}c{z}{s}"{z}
540+
{s}t"{z}{s}a<<{z}{s}b>>{z}{s}c{z}{s}"{z}
541+
{s}f"{z}{s}<<{z}{o}<{z}{n}0{z}{o}>{z}{s}>>{z}{s}"{z}
542+
{s}f"{z}{o}<{z} {o}<{z}{n}0{z}{o}>{z} {o}>{z}{s}"{z}
543+
"""
544+
).format(**colors).replace("<", "{").replace(">", "}")
545+
events = code_to_events(code)
546+
reader, _ = handle_all_events(events)
547+
self.assert_screen_equal(reader, code, clean=True)
548+
self.maxDiff=None
549+
self.assert_screen_equal(reader, expected)
550+
520551
def test_control_characters(self):
521552
code = 'flag = "🏳️‍🌈"'
522553
events = code_to_events(code)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix coloring of double braces in f-strings and t-strings in the :term:`REPL`.

Tools/cases_generator/opcode_metadata_generator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ def generate_deopt_table(analysis: Analysis, out: CWriter) -> None:
157157
if inst.family is not None:
158158
deopt = inst.family.name
159159
deopts.append((inst.name, deopt))
160+
defined = set(analysis.opmap.values())
161+
for i in range(256):
162+
if i not in defined:
163+
deopts.append((f'{i}', f'{i}'))
164+
165+
assert len(deopts) == 256
166+
assert len(set(x[0] for x in deopts)) == 256
160167
for name, deopt in sorted(deopts):
161168
out.emit(f"[{name}] = {deopt},\n")
162169
out.emit("};\n\n")

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