Skip to content

Commit 673fdb2

Browse files
committed
updated to python 3.9.7
1 parent 16d7b47 commit 673fdb2

File tree

141 files changed

+1817
-717
lines changed

Some content is hidden

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

141 files changed

+1817
-717
lines changed

PythonLib/full/_collections_abc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ def _hash(self):
642642
hx = hash(x)
643643
h ^= (hx ^ (hx << 16) ^ 89869747) * 3644798167
644644
h &= MASK
645+
h ^= (h >> 11) ^ (h >> 25)
645646
h = h * 69069 + 907133923
646647
h &= MASK
647648
if h > MAX:

PythonLib/full/_weakrefset.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ def _remove(item, selfref=ref(self)):
5151
self.update(data)
5252

5353
def _commit_removals(self):
54-
l = self._pending_removals
54+
pop = self._pending_removals.pop
5555
discard = self.data.discard
56-
while l:
57-
discard(l.pop())
56+
while True:
57+
try:
58+
item = pop()
59+
except IndexError:
60+
return
61+
discard(item)
5862

5963
def __iter__(self):
6064
with _IterationGuard(self):

PythonLib/full/argparse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ def _get_action_name(argument):
727727
return argument.metavar
728728
elif argument.dest not in (None, SUPPRESS):
729729
return argument.dest
730+
elif argument.choices:
731+
return '{' + ','.join(argument.choices) + '}'
730732
else:
731733
return None
732734

@@ -873,7 +875,7 @@ def __init__(self,
873875
_option_strings.append(option_string)
874876

875877
if help is not None and default is not None:
876-
help += f" (default: {default})"
878+
help += " (default: %(default)s)"
877879

878880
super().__init__(
879881
option_strings=_option_strings,

PythonLib/full/asyncio/tasks.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,16 +635,17 @@ def __sleep0():
635635

636636
async def sleep(delay, result=None, *, loop=None):
637637
"""Coroutine that completes after a given time (in seconds)."""
638+
if loop is not None:
639+
warnings.warn("The loop argument is deprecated since Python 3.8, "
640+
"and scheduled for removal in Python 3.10.",
641+
DeprecationWarning, stacklevel=2)
642+
638643
if delay <= 0:
639644
await __sleep0()
640645
return result
641646

642647
if loop is None:
643648
loop = events.get_running_loop()
644-
else:
645-
warnings.warn("The loop argument is deprecated since Python 3.8, "
646-
"and scheduled for removal in Python 3.10.",
647-
DeprecationWarning, stacklevel=2)
648649

649650
future = loop.create_future()
650651
h = loop.call_later(delay,
@@ -750,13 +751,14 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
750751
after catching an exception (raised by one of the awaitables) from
751752
gather won't cancel any other awaitables.
752753
"""
754+
if loop is not None:
755+
warnings.warn("The loop argument is deprecated since Python 3.8, "
756+
"and scheduled for removal in Python 3.10.",
757+
DeprecationWarning, stacklevel=2)
758+
753759
if not coros_or_futures:
754760
if loop is None:
755761
loop = events.get_event_loop()
756-
else:
757-
warnings.warn("The loop argument is deprecated since Python 3.8, "
758-
"and scheduled for removal in Python 3.10.",
759-
DeprecationWarning, stacklevel=2)
760762
outer = loop.create_future()
761763
outer.set_result([])
762764
return outer

PythonLib/full/asyncio/threads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def to_thread(func, /, *args, **kwargs):
1313
"""Asynchronously run function *func* in a separate thread.
1414
1515
Any *args and **kwargs supplied for this function are directly passed
16-
to *func*. Also, the current :class:`contextvars.Context` is propogated,
16+
to *func*. Also, the current :class:`contextvars.Context` is propagated,
1717
allowing context variables from the main thread to be accessed in the
1818
separate thread.
1919

PythonLib/full/compileall.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
219219
if not force:
220220
try:
221221
mtime = int(os.stat(fullname).st_mtime)
222-
expect = struct.pack('<4sll', importlib.util.MAGIC_NUMBER,
223-
0, mtime)
222+
expect = struct.pack('<4sLL', importlib.util.MAGIC_NUMBER,
223+
0, mtime & 0xFFFF_FFFF)
224224
for cfile in opt_cfiles.values():
225225
with open(cfile, 'rb') as chandle:
226226
actual = chandle.read(12)
@@ -252,9 +252,8 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
252252
else:
253253
print('*** ', end='')
254254
# escape non-printable characters in msg
255-
msg = err.msg.encode(sys.stdout.encoding,
256-
errors='backslashreplace')
257-
msg = msg.decode(sys.stdout.encoding)
255+
encoding = sys.stdout.encoding or sys.getdefaultencoding()
256+
msg = err.msg.encode(encoding, errors='backslashreplace').decode(encoding)
258257
print(msg)
259258
except (SyntaxError, UnicodeError, OSError) as e:
260259
success = False

PythonLib/full/contextlib.py

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,20 @@ def __init__(self, func, args, kwds):
9797
# for the class instead.
9898
# See http://bugs.python.org/issue19404 for more details.
9999

100-
101-
class _GeneratorContextManager(_GeneratorContextManagerBase,
102-
AbstractContextManager,
103-
ContextDecorator):
104-
"""Helper for @contextmanager decorator."""
105-
106100
def _recreate_cm(self):
107-
# _GCM instances are one-shot context managers, so the
101+
# _GCMB instances are one-shot context managers, so the
108102
# CM must be recreated each time a decorated function is
109103
# called
110104
return self.__class__(self.func, self.args, self.kwds)
111105

106+
107+
class _GeneratorContextManager(
108+
_GeneratorContextManagerBase,
109+
AbstractContextManager,
110+
ContextDecorator,
111+
):
112+
"""Helper for @contextmanager decorator."""
113+
112114
def __enter__(self):
113115
# do not keep args and kwds alive unnecessarily
114116
# they are only needed for recreation, which is not possible anymore
@@ -118,8 +120,8 @@ def __enter__(self):
118120
except StopIteration:
119121
raise RuntimeError("generator didn't yield") from None
120122

121-
def __exit__(self, type, value, traceback):
122-
if type is None:
123+
def __exit__(self, typ, value, traceback):
124+
if typ is None:
123125
try:
124126
next(self.gen)
125127
except StopIteration:
@@ -130,9 +132,9 @@ def __exit__(self, type, value, traceback):
130132
if value is None:
131133
# Need to force instantiation so we can reliably
132134
# tell if we get the same exception back
133-
value = type()
135+
value = typ()
134136
try:
135-
self.gen.throw(type, value, traceback)
137+
self.gen.throw(typ, value, traceback)
136138
except StopIteration as exc:
137139
# Suppress StopIteration *unless* it's the same exception that
138140
# was passed to throw(). This prevents a StopIteration
@@ -142,35 +144,39 @@ def __exit__(self, type, value, traceback):
142144
# Don't re-raise the passed in exception. (issue27122)
143145
if exc is value:
144146
return False
145-
# Likewise, avoid suppressing if a StopIteration exception
147+
# Avoid suppressing if a StopIteration exception
146148
# was passed to throw() and later wrapped into a RuntimeError
147-
# (see PEP 479).
148-
if type is StopIteration and exc.__cause__ is value:
149+
# (see PEP 479 for sync generators; async generators also
150+
# have this behavior). But do this only if the exception wrapped
151+
# by the RuntimeError is actually Stop(Async)Iteration (see
152+
# issue29692).
153+
if (
154+
isinstance(value, StopIteration)
155+
and exc.__cause__ is value
156+
):
149157
return False
150158
raise
151-
except:
159+
except BaseException as exc:
152160
# only re-raise if it's *not* the exception that was
153161
# passed to throw(), because __exit__() must not raise
154162
# an exception unless __exit__() itself failed. But throw()
155163
# has to raise the exception to signal propagation, so this
156164
# fixes the impedance mismatch between the throw() protocol
157165
# and the __exit__() protocol.
158-
#
159-
# This cannot use 'except BaseException as exc' (as in the
160-
# async implementation) to maintain compatibility with
161-
# Python 2, where old-style class exceptions are not caught
162-
# by 'except BaseException'.
163-
if sys.exc_info()[1] is value:
164-
return False
165-
raise
166+
if exc is not value:
167+
raise
168+
return False
166169
raise RuntimeError("generator didn't stop after throw()")
167170

168171

169172
class _AsyncGeneratorContextManager(_GeneratorContextManagerBase,
170173
AbstractAsyncContextManager):
171-
"""Helper for @asynccontextmanager."""
174+
"""Helper for @asynccontextmanager decorator."""
172175

173176
async def __aenter__(self):
177+
# do not keep args and kwds alive unnecessarily
178+
# they are only needed for recreation, which is not possible anymore
179+
del self.args, self.kwds, self.func
174180
try:
175181
return await self.gen.__anext__()
176182
except StopAsyncIteration:
@@ -181,35 +187,48 @@ async def __aexit__(self, typ, value, traceback):
181187
try:
182188
await self.gen.__anext__()
183189
except StopAsyncIteration:
184-
return
190+
return False
185191
else:
186192
raise RuntimeError("generator didn't stop")
187193
else:
188194
if value is None:
195+
# Need to force instantiation so we can reliably
196+
# tell if we get the same exception back
189197
value = typ()
190-
# See _GeneratorContextManager.__exit__ for comments on subtleties
191-
# in this implementation
192198
try:
193199
await self.gen.athrow(typ, value, traceback)
194-
raise RuntimeError("generator didn't stop after athrow()")
195200
except StopAsyncIteration as exc:
201+
# Suppress StopIteration *unless* it's the same exception that
202+
# was passed to throw(). This prevents a StopIteration
203+
# raised inside the "with" statement from being suppressed.
196204
return exc is not value
197205
except RuntimeError as exc:
206+
# Don't re-raise the passed in exception. (issue27122)
198207
if exc is value:
199208
return False
200-
# Avoid suppressing if a StopIteration exception
201-
# was passed to throw() and later wrapped into a RuntimeError
209+
# Avoid suppressing if a Stop(Async)Iteration exception
210+
# was passed to athrow() and later wrapped into a RuntimeError
202211
# (see PEP 479 for sync generators; async generators also
203212
# have this behavior). But do this only if the exception wrapped
204213
# by the RuntimeError is actully Stop(Async)Iteration (see
205214
# issue29692).
206-
if isinstance(value, (StopIteration, StopAsyncIteration)):
207-
if exc.__cause__ is value:
208-
return False
215+
if (
216+
isinstance(value, (StopIteration, StopAsyncIteration))
217+
and exc.__cause__ is value
218+
):
219+
return False
209220
raise
210221
except BaseException as exc:
222+
# only re-raise if it's *not* the exception that was
223+
# passed to throw(), because __exit__() must not raise
224+
# an exception unless __exit__() itself failed. But throw()
225+
# has to raise the exception to signal propagation, so this
226+
# fixes the impedance mismatch between the throw() protocol
227+
# and the __exit__() protocol.
211228
if exc is not value:
212229
raise
230+
return False
231+
raise RuntimeError("generator didn't stop after athrow()")
213232

214233

215234
def contextmanager(func):

PythonLib/full/ctypes/test/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class S8I(Structure):
389389
(9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
390390

391391
def test_sf1651235(self):
392-
# see http://www.python.org/sf/1651235
392+
# see https://www.python.org/sf/1651235
393393

394394
proto = CFUNCTYPE(c_int, RECT, POINT)
395395
def callback(*args):

PythonLib/full/ctypes/test/test_loading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_1703286_A(self):
9191
# NOT fit into a 32-bit integer. FreeLibrary must be able
9292
# to accept this address.
9393

94-
# These are tests for http://www.python.org/sf/1703286
94+
# These are tests for https://www.python.org/sf/1703286
9595
handle = LoadLibrary("advapi32")
9696
FreeLibrary(handle)
9797

PythonLib/full/distutils/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ This directory contains the Distutils package.
22

33
There's a full documentation available at:
44

5-
http://docs.python.org/distutils/
5+
https://docs.python.org/distutils/
66

77
The Distutils-SIG web page is also a good starting point:
88

9-
http://www.python.org/sigs/distutils-sig/
9+
https://www.python.org/sigs/distutils-sig/
1010

1111
$Id$

0 commit comments

Comments
 (0)