Skip to content

Commit bf5ef59

Browse files
committed
python 3.12.4
1 parent 29d1d1a commit bf5ef59

File tree

127 files changed

+1441
-935
lines changed

Some content is hidden

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

127 files changed

+1441
-935
lines changed

.github/workflows/CI_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
if: matrix.build_configuration == 'Release'
4444
working-directory: installer
4545
run: |
46-
$env:PYTHONBUILDDIR_X64='..\packages\python.3.12.3\tools'
47-
$env:PYTHONBUILDDIR='..\packages\pythonx86.3.12.3\tools'
46+
$env:PYTHONBUILDDIR_X64='..\packages\python.3.12.4\tools'
47+
$env:PYTHONBUILDDIR='..\packages\pythonx86.3.12.4\tools'
4848
Rename-Item -Path ".\buildPaths.bat.orig" -NewName "buildPaths.bat"
4949
$env:WIX_PATH="C:\Program Files (x86)\WiX Toolset v3.11\bin"
5050
$env:PATH = $env:PATH + ';' + $env:WIX_PATH

PythonLib/full/_pydecimal.py

Lines changed: 16 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -13,104 +13,7 @@
1313
# bug) and will be backported. At this point the spec is stabilizing
1414
# and the updates are becoming fewer, smaller, and less significant.
1515

16-
"""
17-
This is an implementation of decimal floating point arithmetic based on
18-
the General Decimal Arithmetic Specification:
19-
20-
http://speleotrove.com/decimal/decarith.html
21-
22-
and IEEE standard 854-1987:
23-
24-
http://en.wikipedia.org/wiki/IEEE_854-1987
25-
26-
Decimal floating point has finite precision with arbitrarily large bounds.
27-
28-
The purpose of this module is to support arithmetic using familiar
29-
"schoolhouse" rules and to avoid some of the tricky representation
30-
issues associated with binary floating point. The package is especially
31-
useful for financial applications or for contexts where users have
32-
expectations that are at odds with binary floating point (for instance,
33-
in binary floating point, 1.00 % 0.1 gives 0.09999999999999995 instead
34-
of 0.0; Decimal('1.00') % Decimal('0.1') returns the expected
35-
Decimal('0.00')).
36-
37-
Here are some examples of using the decimal module:
38-
39-
>>> from decimal import *
40-
>>> setcontext(ExtendedContext)
41-
>>> Decimal(0)
42-
Decimal('0')
43-
>>> Decimal('1')
44-
Decimal('1')
45-
>>> Decimal('-.0123')
46-
Decimal('-0.0123')
47-
>>> Decimal(123456)
48-
Decimal('123456')
49-
>>> Decimal('123.45e12345678')
50-
Decimal('1.2345E+12345680')
51-
>>> Decimal('1.33') + Decimal('1.27')
52-
Decimal('2.60')
53-
>>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41')
54-
Decimal('-2.20')
55-
>>> dig = Decimal(1)
56-
>>> print(dig / Decimal(3))
57-
0.333333333
58-
>>> getcontext().prec = 18
59-
>>> print(dig / Decimal(3))
60-
0.333333333333333333
61-
>>> print(dig.sqrt())
62-
1
63-
>>> print(Decimal(3).sqrt())
64-
1.73205080756887729
65-
>>> print(Decimal(3) ** 123)
66-
4.85192780976896427E+58
67-
>>> inf = Decimal(1) / Decimal(0)
68-
>>> print(inf)
69-
Infinity
70-
>>> neginf = Decimal(-1) / Decimal(0)
71-
>>> print(neginf)
72-
-Infinity
73-
>>> print(neginf + inf)
74-
NaN
75-
>>> print(neginf * inf)
76-
-Infinity
77-
>>> print(dig / 0)
78-
Infinity
79-
>>> getcontext().traps[DivisionByZero] = 1
80-
>>> print(dig / 0)
81-
Traceback (most recent call last):
82-
...
83-
...
84-
...
85-
decimal.DivisionByZero: x / 0
86-
>>> c = Context()
87-
>>> c.traps[InvalidOperation] = 0
88-
>>> print(c.flags[InvalidOperation])
89-
0
90-
>>> c.divide(Decimal(0), Decimal(0))
91-
Decimal('NaN')
92-
>>> c.traps[InvalidOperation] = 1
93-
>>> print(c.flags[InvalidOperation])
94-
1
95-
>>> c.flags[InvalidOperation] = 0
96-
>>> print(c.flags[InvalidOperation])
97-
0
98-
>>> print(c.divide(Decimal(0), Decimal(0)))
99-
Traceback (most recent call last):
100-
...
101-
...
102-
...
103-
decimal.InvalidOperation: 0 / 0
104-
>>> print(c.flags[InvalidOperation])
105-
1
106-
>>> c.flags[InvalidOperation] = 0
107-
>>> c.traps[InvalidOperation] = 0
108-
>>> print(c.divide(Decimal(0), Decimal(0)))
109-
NaN
110-
>>> print(c.flags[InvalidOperation])
111-
1
112-
>>>
113-
"""
16+
"""Python decimal arithmetic module"""
11417

11518
__all__ = [
11619
# Two major classes
@@ -2228,10 +2131,16 @@ def _power_exact(self, other, p):
22282131
else:
22292132
return None
22302133

2231-
if xc >= 10**p:
2134+
# An exact power of 10 is representable, but can convert to a
2135+
# string of any length. But an exact power of 10 shouldn't be
2136+
# possible at this point.
2137+
assert xc > 1, self
2138+
assert xc % 10 != 0, self
2139+
strxc = str(xc)
2140+
if len(strxc) > p:
22322141
return None
22332142
xe = -e-xe
2234-
return _dec_from_triple(0, str(xc), xe)
2143+
return _dec_from_triple(0, strxc, xe)
22352144

22362145
# now y is positive; find m and n such that y = m/n
22372146
if ye >= 0:
@@ -2281,13 +2190,18 @@ def _power_exact(self, other, p):
22812190
return None
22822191
xc = xc**m
22832192
xe *= m
2284-
if xc > 10**p:
2193+
# An exact power of 10 is representable, but can convert to a string
2194+
# of any length. But an exact power of 10 shouldn't be possible at
2195+
# this point.
2196+
assert xc > 1, self
2197+
assert xc % 10 != 0, self
2198+
str_xc = str(xc)
2199+
if len(str_xc) > p:
22852200
return None
22862201

22872202
# by this point the result *is* exactly representable
22882203
# adjust the exponent to get as close as possible to the ideal
22892204
# exponent, if necessary
2290-
str_xc = str(xc)
22912205
if other._isinteger() and other._sign == 0:
22922206
ideal_exponent = self._exp*int(other)
22932207
zeros = min(xe-ideal_exponent, p-len(str_xc))

PythonLib/full/_pylong.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
import re
1616
import decimal
17+
try:
18+
import _decimal
19+
except ImportError:
20+
_decimal = None
1721

1822

1923
def int_to_decimal(n):
@@ -82,7 +86,47 @@ def inner(n, w):
8286

8387
def int_to_decimal_string(n):
8488
"""Asymptotically fast conversion of an 'int' to a decimal string."""
85-
return str(int_to_decimal(n))
89+
w = n.bit_length()
90+
if w > 450_000 and _decimal is not None:
91+
# It is only usable with the C decimal implementation.
92+
# _pydecimal.py calls str() on very large integers, which in its
93+
# turn calls int_to_decimal_string(), causing very deep recursion.
94+
return str(int_to_decimal(n))
95+
96+
# Fallback algorithm for the case when the C decimal module isn't
97+
# available. This algorithm is asymptotically worse than the algorithm
98+
# using the decimal module, but better than the quadratic time
99+
# implementation in longobject.c.
100+
def inner(n, w):
101+
if w <= 1000:
102+
return str(n)
103+
w2 = w >> 1
104+
d = pow10_cache.get(w2)
105+
if d is None:
106+
d = pow10_cache[w2] = 5**w2 << w2 # 10**i = (5*2)**i = 5**i * 2**i
107+
hi, lo = divmod(n, d)
108+
return inner(hi, w - w2) + inner(lo, w2).zfill(w2)
109+
110+
# The estimation of the number of decimal digits.
111+
# There is no harm in small error. If we guess too large, there may
112+
# be leading 0's that need to be stripped. If we guess too small, we
113+
# may need to call str() recursively for the remaining highest digits,
114+
# which can still potentially be a large integer. This is manifested
115+
# only if the number has way more than 10**15 digits, that exceeds
116+
# the 52-bit physical address limit in both Intel64 and AMD64.
117+
w = int(w * 0.3010299956639812 + 1) # log10(2)
118+
pow10_cache = {}
119+
if n < 0:
120+
n = -n
121+
sign = '-'
122+
else:
123+
sign = ''
124+
s = inner(n, w)
125+
if s[0] == '0' and n:
126+
# If our guess of w is too large, there may be leading 0's that
127+
# need to be stripped.
128+
s = s.lstrip('0')
129+
return sign + s
86130

87131

88132
def _str_to_int_inner(s):

PythonLib/full/asyncio/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class AsyncIOInteractiveConsole(code.InteractiveConsole):
1616
def __init__(self, locals, loop):
1717
super().__init__(locals)
1818
self.compile.compiler.flags |= ast.PyCF_ALLOW_TOP_LEVEL_AWAIT
19-
2019
self.loop = loop
2120

2221
def runcode(self, code):

PythonLib/full/asyncio/proactor_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ async def sock_sendto(self, sock, data, address):
724724
return await self._proactor.sendto(sock, data, 0, address)
725725

726726
async def sock_connect(self, sock, address):
727+
if self._debug and sock.gettimeout() != 0:
728+
raise ValueError("the socket must be non-blocking")
727729
return await self._proactor.connect(sock, address)
728730

729731
async def sock_accept(self, sock):

PythonLib/full/base64.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
334334
335335
wrapcol controls whether the output should have newline (b'\\n') characters
336336
added to it. If this is non-zero, each output line will be at most this
337-
many characters long.
337+
many characters long, excluding the trailing newline.
338338
339339
pad controls whether the input is padded to a multiple of 4 before
340340
encoding. Note that the btoa implementation always pads.

PythonLib/full/bdb.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ def dispatch_return(self, frame, arg):
157157
# The user issued a 'next' or 'until' command.
158158
if self.stopframe is frame and self.stoplineno != -1:
159159
self._set_stopinfo(None, None)
160+
# The previous frame might not have f_trace set, unless we are
161+
# issuing a command that does not expect to stop, we should set
162+
# f_trace
163+
if self.stoplineno != -1:
164+
self._set_caller_tracefunc(frame)
160165
return self.trace_dispatch
161166

162167
def dispatch_exception(self, frame, arg):
@@ -286,6 +291,15 @@ def _set_stopinfo(self, stopframe, returnframe, stoplineno=0):
286291
# stoplineno -1 means: don't stop at all
287292
self.stoplineno = stoplineno
288293

294+
def _set_caller_tracefunc(self, current_frame):
295+
# Issue #13183: pdb skips frames after hitting a breakpoint and running
296+
# step commands.
297+
# Restore the trace function in the caller (that may not have been set
298+
# for performance reasons) when returning from the current frame.
299+
caller_frame = current_frame.f_back
300+
if caller_frame and not caller_frame.f_trace:
301+
caller_frame.f_trace = self.trace_dispatch
302+
289303
# Derived classes and clients can call the following methods
290304
# to affect the stepping state.
291305

@@ -299,14 +313,6 @@ def set_until(self, frame, lineno=None):
299313

300314
def set_step(self):
301315
"""Stop after one line of code."""
302-
# Issue #13183: pdb skips frames after hitting a breakpoint and running
303-
# step commands.
304-
# Restore the trace function in the caller (that may not have been set
305-
# for performance reasons) when returning from the current frame.
306-
if self.frame_returning:
307-
caller_frame = self.frame_returning.f_back
308-
if caller_frame and not caller_frame.f_trace:
309-
caller_frame.f_trace = self.trace_dispatch
310316
self._set_stopinfo(None, None)
311317

312318
def set_next(self, frame):

PythonLib/full/ctypes/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ def cast(obj, typ):
519519

520520
_string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
521521
def string_at(ptr, size=-1):
522-
"""string_at(addr[, size]) -> string
522+
"""string_at(ptr[, size]) -> string
523523
524-
Return the string at addr."""
524+
Return the byte string at void *ptr."""
525525
return _string_at(ptr, size)
526526

527527
try:
@@ -531,9 +531,9 @@ def string_at(ptr, size=-1):
531531
else:
532532
_wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
533533
def wstring_at(ptr, size=-1):
534-
"""wstring_at(addr[, size]) -> string
534+
"""wstring_at(ptr[, size]) -> string
535535
536-
Return the string at addr."""
536+
Return the wide-character string at void *ptr."""
537537
return _wstring_at(ptr, size)
538538

539539

PythonLib/full/dataclasses.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,17 @@ def _dataclass_setstate(self, state):
11681168

11691169
def _get_slots(cls):
11701170
match cls.__dict__.get('__slots__'):
1171-
# A class which does not define __slots__ at all is equivalent
1172-
# to a class defining __slots__ = ('__dict__', '__weakref__')
1171+
# `__dictoffset__` and `__weakrefoffset__` can tell us whether
1172+
# the base type has dict/weakref slots, in a way that works correctly
1173+
# for both Python classes and C extension types. Extension types
1174+
# don't use `__slots__` for slot creation
11731175
case None:
1174-
yield from ('__dict__', '__weakref__')
1176+
slots = []
1177+
if getattr(cls, '__weakrefoffset__', -1) != 0:
1178+
slots.append('__weakref__')
1179+
if getattr(cls, '__dictrefoffset__', -1) != 0:
1180+
slots.append('__dict__')
1181+
yield from slots
11751182
case str(slot):
11761183
yield slot
11771184
# Slots may be any iterable, but we cannot handle an iterator

0 commit comments

Comments
 (0)