Skip to content

Commit 4dfa498

Browse files
committed
update to python 3.8.4
1 parent 7118180 commit 4dfa498

File tree

114 files changed

+512
-447
lines changed

Some content is hidden

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

114 files changed

+512
-447
lines changed

PythonLib/full/ast.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ def __instancecheck__(cls, inst):
483483
return type.__instancecheck__(cls, inst)
484484

485485
def _new(cls, *args, **kwargs):
486+
for key in kwargs:
487+
if key not in cls._fields:
488+
# arbitrary keyword arguments are accepted
489+
continue
490+
pos = cls._fields.index(key)
491+
if pos < len(args):
492+
raise TypeError(f"{cls.__name__} got multiple values for argument {key!r}")
486493
if cls in _const_types:
487494
return Constant(*args, **kwargs)
488495
return Constant.__new__(cls, *args, **kwargs)

PythonLib/full/asyncio/unix_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def add_signal_handler(self, sig, callback, *args):
101101

102102
try:
103103
# Register a dummy signal handler to ask Python to write the signal
104-
# number in the wakup file descriptor. _process_self_data() will
104+
# number in the wakeup file descriptor. _process_self_data() will
105105
# read signal numbers from this file descriptor to handle signals.
106106
signal.signal(sig, _sighandler_noop)
107107

PythonLib/full/cgi.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ def parse_multipart(fp, pdict, encoding="utf-8", errors="replace"):
200200
ctype = "multipart/form-data; boundary={}".format(boundary)
201201
headers = Message()
202202
headers.set_type(ctype)
203-
headers['Content-Length'] = pdict['CONTENT-LENGTH']
203+
try:
204+
headers['Content-Length'] = pdict['CONTENT-LENGTH']
205+
except KeyError:
206+
pass
204207
fs = FieldStorage(fp, headers=headers, encoding=encoding, errors=errors,
205208
environ={'REQUEST_METHOD': 'POST'})
206209
return {k: fs.getlist(k) for k in fs}
@@ -736,7 +739,8 @@ def read_lines_to_outerboundary(self):
736739
last_line_lfend = True
737740
_read = 0
738741
while 1:
739-
if self.limit is not None and _read >= self.limit:
742+
743+
if self.limit is not None and 0 <= self.limit <= _read:
740744
break
741745
line = self.fp.readline(1<<16) # bytes
742746
self.bytes_read += len(line)

PythonLib/full/codeop.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"""
5858

5959
import __future__
60+
import warnings
6061

6162
_features = [getattr(__future__, fname)
6263
for fname in __future__.all_feature_names]
@@ -83,15 +84,18 @@ def _maybe_compile(compiler, source, filename, symbol):
8384
except SyntaxError as err:
8485
pass
8586

86-
try:
87-
code1 = compiler(source + "\n", filename, symbol)
88-
except SyntaxError as e:
89-
err1 = e
87+
# Suppress warnings after the first compile to avoid duplication.
88+
with warnings.catch_warnings():
89+
warnings.simplefilter("ignore")
90+
try:
91+
code1 = compiler(source + "\n", filename, symbol)
92+
except SyntaxError as e:
93+
err1 = e
9094

91-
try:
92-
code2 = compiler(source + "\n\n", filename, symbol)
93-
except SyntaxError as e:
94-
err2 = e
95+
try:
96+
code2 = compiler(source + "\n\n", filename, symbol)
97+
except SyntaxError as e:
98+
err2 = e
9599

96100
try:
97101
if code:
@@ -112,7 +116,8 @@ def compile_command(source, filename="<input>", symbol="single"):
112116
source -- the source string; may contain \n characters
113117
filename -- optional filename from which source was read; default
114118
"<input>"
115-
symbol -- optional grammar start symbol; "single" (default) or "eval"
119+
symbol -- optional grammar start symbol; "single" (default), "exec"
120+
or "eval"
116121
117122
Return value / exceptions raised:
118123

PythonLib/full/ctypes/test/test_callbacks.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import functools
22
import unittest
3+
from test import support
4+
35
from ctypes import *
46
from ctypes.test import need_symbol
57
import _ctypes_test
@@ -287,7 +289,36 @@ def callback(check, s):
287289
self.assertEqual(s.second, check.second)
288290
self.assertEqual(s.third, check.third)
289291

290-
################################################################
292+
def test_callback_too_many_args(self):
293+
def func(*args):
294+
return len(args)
295+
296+
CTYPES_MAX_ARGCOUNT = 1024
297+
proto = CFUNCTYPE(c_int, *(c_int,) * CTYPES_MAX_ARGCOUNT)
298+
cb = proto(func)
299+
args1 = (1,) * CTYPES_MAX_ARGCOUNT
300+
self.assertEqual(cb(*args1), CTYPES_MAX_ARGCOUNT)
301+
302+
args2 = (1,) * (CTYPES_MAX_ARGCOUNT + 1)
303+
with self.assertRaises(ArgumentError):
304+
cb(*args2)
305+
306+
def test_convert_result_error(self):
307+
def func():
308+
return ("tuple",)
309+
310+
proto = CFUNCTYPE(c_int)
311+
ctypes_func = proto(func)
312+
with support.catch_unraisable_exception() as cm:
313+
# don't test the result since it is an uninitialized value
314+
result = ctypes_func()
315+
316+
self.assertIsInstance(cm.unraisable.exc_value, TypeError)
317+
self.assertEqual(cm.unraisable.err_msg,
318+
"Exception ignored on converting result "
319+
"of ctypes callback function")
320+
self.assertIs(cm.unraisable.object, func)
321+
291322

292323
if __name__ == '__main__':
293324
unittest.main()

PythonLib/full/ctypes/test/test_loading.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,9 @@ def should_fail(command):
158158
# Relative path (but not just filename) should succeed
159159
should_pass("WinDLL('./_sqlite3.dll')")
160160

161-
# XXX: This test has started failing on Azure Pipelines CI. See
162-
# bpo-40214 for more information.
163-
if 0:
164-
# Insecure load flags should succeed
165-
should_pass("WinDLL('_sqlite3.dll', winmode=0)")
161+
# Insecure load flags should succeed
162+
# Clear the DLL directory to avoid safe search settings propagating
163+
should_pass("windll.kernel32.SetDllDirectoryW(None); WinDLL('_sqlite3.dll', winmode=0)")
166164

167165
# Full path load without DLL_LOAD_DIR shouldn't find dependency
168166
should_fail("WinDLL(nt._getfullpathname('_sqlite3.dll'), " +

PythonLib/full/ctypes/test/test_random_things.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from ctypes import *
2-
import unittest, sys
2+
import contextlib
3+
from test import support
4+
import unittest
5+
import sys
6+
37

48
def callback_func(arg):
59
42 / arg
@@ -34,41 +38,40 @@ class CallbackTracbackTestCase(unittest.TestCase):
3438
# created, then a full traceback printed. When SystemExit is
3539
# raised in a callback function, the interpreter exits.
3640

37-
def capture_stderr(self, func, *args, **kw):
38-
# helper - call function 'func', and return the captured stderr
39-
import io
40-
old_stderr = sys.stderr
41-
logger = sys.stderr = io.StringIO()
42-
try:
43-
func(*args, **kw)
44-
finally:
45-
sys.stderr = old_stderr
46-
return logger.getvalue()
41+
@contextlib.contextmanager
42+
def expect_unraisable(self, exc_type, exc_msg=None):
43+
with support.catch_unraisable_exception() as cm:
44+
yield
45+
46+
self.assertIsInstance(cm.unraisable.exc_value, exc_type)
47+
if exc_msg is not None:
48+
self.assertEqual(str(cm.unraisable.exc_value), exc_msg)
49+
self.assertEqual(cm.unraisable.err_msg,
50+
"Exception ignored on calling ctypes "
51+
"callback function")
52+
self.assertIs(cm.unraisable.object, callback_func)
4753

4854
def test_ValueError(self):
4955
cb = CFUNCTYPE(c_int, c_int)(callback_func)
50-
out = self.capture_stderr(cb, 42)
51-
self.assertEqual(out.splitlines()[-1],
52-
"ValueError: 42")
56+
with self.expect_unraisable(ValueError, '42'):
57+
cb(42)
5358

5459
def test_IntegerDivisionError(self):
5560
cb = CFUNCTYPE(c_int, c_int)(callback_func)
56-
out = self.capture_stderr(cb, 0)
57-
self.assertEqual(out.splitlines()[-1][:19],
58-
"ZeroDivisionError: ")
61+
with self.expect_unraisable(ZeroDivisionError):
62+
cb(0)
5963

6064
def test_FloatDivisionError(self):
6165
cb = CFUNCTYPE(c_int, c_double)(callback_func)
62-
out = self.capture_stderr(cb, 0.0)
63-
self.assertEqual(out.splitlines()[-1][:19],
64-
"ZeroDivisionError: ")
66+
with self.expect_unraisable(ZeroDivisionError):
67+
cb(0.0)
6568

6669
def test_TypeErrorDivisionError(self):
6770
cb = CFUNCTYPE(c_int, c_char_p)(callback_func)
68-
out = self.capture_stderr(cb, b"spam")
69-
self.assertEqual(out.splitlines()[-1],
70-
"TypeError: "
71-
"unsupported operand type(s) for /: 'int' and 'bytes'")
71+
err_msg = "unsupported operand type(s) for /: 'int' and 'bytes'"
72+
with self.expect_unraisable(TypeError, err_msg):
73+
cb(b"spam")
74+
7275

7376
if __name__ == '__main__':
7477
unittest.main()

PythonLib/full/ctypes/test/test_unaligned_structures.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ class Y(SwappedStructure):
2727
class TestStructures(unittest.TestCase):
2828
def test_native(self):
2929
for typ in structures:
30-
## print typ.value
3130
self.assertEqual(typ.value.offset, 1)
3231
o = typ()
3332
o.value = 4
3433
self.assertEqual(o.value, 4)
3534

3635
def test_swapped(self):
3736
for typ in byteswapped_structures:
38-
## print >> sys.stderr, typ.value
3937
self.assertEqual(typ.value.offset, 1)
4038
o = typ()
4139
o.value = 4

PythonLib/full/dataclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ def _asdict_inner(obj, dict_factory):
10921092
# method, because:
10931093
# - it does not recurse in to the namedtuple fields and
10941094
# convert them to dicts (using dict_factory).
1095-
# - I don't actually want to return a dict here. The the main
1095+
# - I don't actually want to return a dict here. The main
10961096
# use case here is json.dumps, and it handles converting
10971097
# namedtuples to lists. Admittedly we're losing some
10981098
# information here when we produce a json list instead of a

PythonLib/full/distutils/command/build_py.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import importlib.util
77
import sys
8-
from glob import glob
8+
import glob
99

1010
from distutils.core import Command
1111
from distutils.errors import *
@@ -125,7 +125,7 @@ def find_data_files(self, package, src_dir):
125125
files = []
126126
for pattern in globs:
127127
# Each pattern has to be converted to a platform-specific path
128-
filelist = glob(os.path.join(src_dir, convert_path(pattern)))
128+
filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern)))
129129
# Files that match more than one pattern are only added once
130130
files.extend([fn for fn in filelist if fn not in files
131131
and os.path.isfile(fn)])
@@ -216,7 +216,7 @@ def check_module(self, module, module_file):
216216

217217
def find_package_modules(self, package, package_dir):
218218
self.check_package(package, package_dir)
219-
module_files = glob(os.path.join(package_dir, "*.py"))
219+
module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
220220
modules = []
221221
setup_script = os.path.abspath(self.distribution.script_name)
222222

0 commit comments

Comments
 (0)