Skip to content

Commit 4306a73

Browse files
committed
Merge remote-tracking branch 'upstream/main' into pep-768
2 parents 139b234 + 03f6c8e commit 4306a73

31 files changed

+305
-295
lines changed

Doc/library/uuid.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,29 @@ which relays any information about the UUID's safety, using this enumeration:
103103
- Meaning
104104

105105
* - .. attribute:: UUID.time_low
106-
- The first 32 bits of the UUID.
106+
- The first 32 bits of the UUID. Only relevant to version 1.
107107

108108
* - .. attribute:: UUID.time_mid
109-
- The next 16 bits of the UUID.
109+
- The next 16 bits of the UUID. Only relevant to version 1.
110110

111111
* - .. attribute:: UUID.time_hi_version
112-
- The next 16 bits of the UUID.
112+
- The next 16 bits of the UUID. Only relevant to version 1.
113113

114114
* - .. attribute:: UUID.clock_seq_hi_variant
115-
- The next 8 bits of the UUID.
115+
- The next 8 bits of the UUID. Only relevant to versions 1 and 6.
116116

117117
* - .. attribute:: UUID.clock_seq_low
118-
- The next 8 bits of the UUID.
118+
- The next 8 bits of the UUID. Only relevant to versions 1 and 6.
119119

120120
* - .. attribute:: UUID.node
121-
- The last 48 bits of the UUID.
121+
- The last 48 bits of the UUID. Only relevant to version 1.
122122

123123
* - .. attribute:: UUID.time
124-
- The 60-bit timestamp.
124+
- The 60-bit timestamp for version 1 and 6,
125+
or the 48-bit timestamp for version 7.
125126

126127
* - .. attribute:: UUID.clock_seq
127-
- The 14-bit sequence number.
128+
- The 14-bit sequence number. Only relevant to versions 1 and 6.
128129

129130

130131
.. attribute:: UUID.hex

Include/internal/mimalloc/mimalloc/atomic.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ static inline void mi_atomic_yield(void) {
338338
_mm_pause();
339339
}
340340
#elif (defined(__GNUC__) || defined(__clang__)) && \
341-
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__armel__) || defined(__ARMEL__) || \
342-
defined(__aarch64__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)) || defined(__POWERPC__)
341+
(defined(__x86_64__) || defined(__i386__) || \
342+
defined(__aarch64__) || defined(__arm__) || \
343+
defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__))
343344
#if defined(__x86_64__) || defined(__i386__)
344345
static inline void mi_atomic_yield(void) {
345346
__asm__ volatile ("pause" ::: "memory");
@@ -348,10 +349,16 @@ static inline void mi_atomic_yield(void) {
348349
static inline void mi_atomic_yield(void) {
349350
__asm__ volatile("wfe");
350351
}
351-
#elif (defined(__arm__) && __ARM_ARCH__ >= 7)
352+
#elif defined(__arm__)
353+
#if __ARM_ARCH >= 7
352354
static inline void mi_atomic_yield(void) {
353355
__asm__ volatile("yield" ::: "memory");
354356
}
357+
#else
358+
static inline void mi_atomic_yield(void) {
359+
__asm__ volatile ("nop" ::: "memory");
360+
}
361+
#endif
355362
#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__)
356363
#ifdef __APPLE__
357364
static inline void mi_atomic_yield(void) {
@@ -362,10 +369,6 @@ static inline void mi_atomic_yield(void) {
362369
__asm__ __volatile__ ("or 27,27,27" ::: "memory");
363370
}
364371
#endif
365-
#elif defined(__armel__) || defined(__ARMEL__)
366-
static inline void mi_atomic_yield(void) {
367-
__asm__ volatile ("nop" ::: "memory");
368-
}
369372
#endif
370373
#elif defined(__sun)
371374
// Fallback for other archs

Lib/functools.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -516,22 +516,6 @@ def _unwrap_partialmethod(func):
516516

517517
_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])
518518

519-
class _HashedSeq(list):
520-
""" This class guarantees that hash() will be called no more than once
521-
per element. This is important because the lru_cache() will hash
522-
the key multiple times on a cache miss.
523-
524-
"""
525-
526-
__slots__ = 'hashvalue'
527-
528-
def __init__(self, tup, hash=hash):
529-
self[:] = tup
530-
self.hashvalue = hash(tup)
531-
532-
def __hash__(self):
533-
return self.hashvalue
534-
535519
def _make_key(args, kwds, typed,
536520
kwd_mark = (object(),),
537521
fasttypes = {int, str},
@@ -561,7 +545,7 @@ def _make_key(args, kwds, typed,
561545
key += tuple(type(v) for v in kwds.values())
562546
elif len(key) == 1 and type(key[0]) in fasttypes:
563547
return key[0]
564-
return _HashedSeq(key)
548+
return key
565549

566550
def lru_cache(maxsize=128, typed=False):
567551
"""Least-recently-used cache decorator.

Lib/test/test_generated_cases.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ def test_effect_sizes(self):
6868
StackItem("b", None, "oparg*4"),
6969
StackItem("c", None, "1"),
7070
]
71-
stack.pop(z)
72-
stack.pop(y)
73-
stack.pop(x)
71+
null = CWriter.null()
72+
stack.pop(z, null)
73+
stack.pop(y, null)
74+
stack.pop(x, null)
7475
for out in outputs:
7576
stack.push(Local.undefined(out))
7677
self.assertEqual(stack.base_offset.to_c(), "-1 - oparg - oparg*2")
77-
self.assertEqual(stack.top_offset.to_c(), "1 - oparg - oparg*2 + oparg*4")
78+
self.assertEqual(stack.physical_sp.to_c(), "0")
79+
self.assertEqual(stack.logical_sp.to_c(), "1 - oparg - oparg*2 + oparg*4")
7880

7981

8082
class TestGeneratedCases(unittest.TestCase):

Lib/test/test_traceback.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4619,7 +4619,31 @@ def test_levenshtein_distance_short_circuit(self):
46194619
@cpython_only
46204620
def test_suggestions_extension(self):
46214621
# Check that the C extension is available
4622-
import _suggestions # noqa: F401
4622+
import _suggestions
4623+
4624+
self.assertEqual(
4625+
_suggestions._generate_suggestions(
4626+
["hello", "world"],
4627+
"hell"
4628+
),
4629+
"hello"
4630+
)
4631+
self.assertEqual(
4632+
_suggestions._generate_suggestions(
4633+
["hovercraft"],
4634+
"eels"
4635+
),
4636+
None
4637+
)
4638+
4639+
# gh-131936: _generate_suggestions() doesn't accept list subclasses
4640+
class MyList(list):
4641+
pass
4642+
4643+
with self.assertRaises(TypeError):
4644+
_suggestions._generate_suggestions(MyList(), "")
4645+
4646+
46234647

46244648

46254649
class TestColorizedTraceback(unittest.TestCase):

Lib/test/test_uuid.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ def test_uuid7(self):
913913
equal(self.uuid._last_counter_v7, counter)
914914

915915
unix_ts_ms = timestamp_ms & 0xffff_ffff_ffff
916+
equal(u.time, unix_ts_ms)
916917
equal((u.int >> 80) & 0xffff_ffff_ffff, unix_ts_ms)
917918

918919
equal((u.int >> 75) & 1, 0) # check that the MSB is 0
@@ -966,6 +967,7 @@ def test_uuid7_monotonicity(self):
966967
urand.assert_called_once_with(10)
967968
equal(self.uuid._last_timestamp_v7, timestamp_ms)
968969
equal(self.uuid._last_counter_v7, counter)
970+
equal(u1.time, timestamp_ms)
969971
equal((u1.int >> 64) & 0xfff, counter_hi)
970972
equal((u1.int >> 32) & 0x3fff_ffff, counter_lo)
971973
equal(u1.int & 0xffff_ffff, tail)
@@ -988,6 +990,7 @@ def test_uuid7_monotonicity(self):
988990
equal(self.uuid._last_timestamp_v7, timestamp_ms)
989991
# 42-bit counter advanced by 1
990992
equal(self.uuid._last_counter_v7, counter + 1)
993+
equal(u2.time, timestamp_ms)
991994
equal((u2.int >> 64) & 0xfff, counter_hi)
992995
equal((u2.int >> 32) & 0x3fff_ffff, counter_lo + 1)
993996
equal(u2.int & 0xffff_ffff, next_fail)
@@ -1025,6 +1028,7 @@ def test_uuid7_timestamp_backwards(self):
10251028
equal(u.version, 7)
10261029
equal(self.uuid._last_timestamp_v7, fake_last_timestamp_v7 + 1)
10271030
unix_ts_ms = (fake_last_timestamp_v7 + 1) & 0xffff_ffff_ffff
1031+
equal(u.time, unix_ts_ms)
10281032
equal((u.int >> 80) & 0xffff_ffff_ffff, unix_ts_ms)
10291033
# 42-bit counter advanced by 1
10301034
equal(self.uuid._last_counter_v7, counter + 1)
@@ -1064,6 +1068,7 @@ def test_uuid7_overflow_counter(self):
10641068
# timestamp advanced due to overflow
10651069
equal(self.uuid._last_timestamp_v7, timestamp_ms + 1)
10661070
unix_ts_ms = (timestamp_ms + 1) & 0xffff_ffff_ffff
1071+
equal(u.time, unix_ts_ms)
10671072
equal((u.int >> 80) & 0xffff_ffff_ffff, unix_ts_ms)
10681073
# counter overflowed, so we picked a new one
10691074
equal(self.uuid._last_counter_v7, new_counter)

Lib/textwrap.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,20 @@ def indent(text, prefix, predicate=None):
451451
it will default to adding 'prefix' to all non-empty lines that do not
452452
consist solely of whitespace characters.
453453
"""
454-
if predicate is None:
455-
# str.splitlines(True) doesn't produce empty string.
456-
# ''.splitlines(True) => []
457-
# 'foo\n'.splitlines(True) => ['foo\n']
458-
# So we can use just `not s.isspace()` here.
459-
predicate = lambda s: not s.isspace()
460-
461454
prefixed_lines = []
462-
for line in text.splitlines(True):
463-
if predicate(line):
464-
prefixed_lines.append(prefix)
465-
prefixed_lines.append(line)
466-
455+
if predicate is None:
456+
# str.splitlines(keepends=True) doesn't produce the empty string,
457+
# so we need to use `str.isspace()` rather than a truth test.
458+
# Inlining the predicate leads to a ~30% performance improvement.
459+
for line in text.splitlines(True):
460+
if not line.isspace():
461+
prefixed_lines.append(prefix)
462+
prefixed_lines.append(line)
463+
else:
464+
for line in text.splitlines(True):
465+
if predicate(line):
466+
prefixed_lines.append(prefix)
467+
prefixed_lines.append(line)
467468
return ''.join(prefixed_lines)
468469

469470

Lib/typing.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@
2929
import operator
3030
import sys
3131
import types
32-
from types import (
33-
WrapperDescriptorType,
34-
MethodWrapperType,
35-
MethodDescriptorType,
36-
GenericAlias,
37-
)
32+
from types import GenericAlias
3833
import warnings
3934

4035
from _typing import (
@@ -354,26 +349,11 @@ def _deduplicate(params, *, unhashable_fallback=False):
354349
if not unhashable_fallback:
355350
raise
356351
# Happens for cases like `Annotated[dict, {'x': IntValidator()}]`
357-
return _deduplicate_unhashable(params)
358-
359-
def _deduplicate_unhashable(unhashable_params):
360-
new_unhashable = []
361-
for t in unhashable_params:
362-
if t not in new_unhashable:
363-
new_unhashable.append(t)
364-
return new_unhashable
365-
366-
def _compare_args_orderless(first_args, second_args):
367-
first_unhashable = _deduplicate_unhashable(first_args)
368-
second_unhashable = _deduplicate_unhashable(second_args)
369-
t = list(second_unhashable)
370-
try:
371-
for elem in first_unhashable:
372-
t.remove(elem)
373-
except ValueError:
374-
return False
375-
return not t
376-
352+
new_unhashable = []
353+
for t in params:
354+
if t not in new_unhashable:
355+
new_unhashable.append(t)
356+
return new_unhashable
377357

378358
def _flatten_literal_params(parameters):
379359
"""Internal helper for Literal creation: flatten Literals among parameters."""

Lib/uuid.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,16 @@ class UUID:
134134
135135
fields a tuple of the six integer fields of the UUID,
136136
which are also available as six individual attributes
137-
and two derived attributes. The time_* attributes are
138-
only relevant to version 1, while the others are only
139-
relevant to versions 1 and 6:
137+
and two derived attributes. Those attributes are not
138+
always relevant to all UUID versions:
139+
140+
The 'time_*' attributes are only relevant to version 1.
141+
142+
The 'clock_seq*' and 'node' attributes are only relevant
143+
to versions 1 and 6.
144+
145+
The 'time' attribute is only relevant to versions 1, 6
146+
and 7.
140147
141148
time_low the first 32 bits of the UUID
142149
time_mid the next 16 bits of the UUID
@@ -145,7 +152,8 @@ class UUID:
145152
clock_seq_low the next 8 bits of the UUID
146153
node the last 48 bits of the UUID
147154
148-
time the 60-bit timestamp
155+
time the 60-bit timestamp for UUIDv1/v6,
156+
or the 48-bit timestamp for UUIDv7
149157
clock_seq the 14-bit sequence number
150158
151159
hex the UUID as a 32-character hexadecimal string
@@ -366,6 +374,9 @@ def time(self):
366374
time_hi = self.int >> 96
367375
time_lo = (self.int >> 64) & 0x0fff
368376
return time_hi << 28 | (self.time_mid << 12) | time_lo
377+
elif self.version == 7:
378+
# unix_ts_ms (48) | ... (80)
379+
return self.int >> 80
369380
else:
370381
# time_lo (32) | time_mid (16) | ver (4) | time_hi (12) | ... (64)
371382
#

Makefile.pre.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ Python/frozen.o: $(FROZEN_FILES_OUT)
20912091
# an include guard, so we can't use a pipeline to transform its output.
20922092
Include/pydtrace_probes.h: $(srcdir)/Include/pydtrace.d
20932093
$(MKDIR_P) Include
2094-
$(DTRACE) $(DFLAGS) -o $@ -h -s $<
2094+
CC="$(CC)" CFLAGS="$(CFLAGS)" $(DTRACE) $(DFLAGS) -o $@ -h -s $<
20952095
: sed in-place edit with POSIX-only tools
20962096
sed 's/PYTHON_/PyDTrace_/' $@ > $@.tmp
20972097
mv $@.tmp $@
@@ -2101,7 +2101,7 @@ Python/gc.o: $(srcdir)/Include/pydtrace.h
21012101
Python/import.o: $(srcdir)/Include/pydtrace.h
21022102

21032103
Python/pydtrace.o: $(srcdir)/Include/pydtrace.d $(DTRACE_DEPS)
2104-
$(DTRACE) $(DFLAGS) -o $@ -G -s $< $(DTRACE_DEPS)
2104+
CC="$(CC)" CFLAGS="$(CFLAGS)" $(DTRACE) $(DFLAGS) -o $@ -G -s $< $(DTRACE_DEPS)
21052105

21062106
Objects/typeobject.o: Objects/typeslots.inc
21072107

0 commit comments

Comments
 (0)