File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -145,3 +145,8 @@ def _check_flags_error(flags):
145145 assert exc .args [0 ] == "incomplete input" , repr (exc )
146146else :
147147 raise AssertionError ("expected _IncompleteInputError" )
148+
149+ # The source is encoded before it is parsed, so a lone surrogate has to be
150+ # reported rather than assumed away.
151+ with assert_raises (UnicodeEncodeError ):
152+ compile (chr (0xD800 ), "<test>" , "eval" )
Original file line number Diff line number Diff line change 1+ from testutils import assert_raises
2+
13assert 3 == eval ("1+2" )
24
35code = compile ("5+3" , "x.py" , "eval" )
@@ -75,3 +77,8 @@ def make_closure():
7577 assert False , "eval with code containing free variables should fail"
7678except NameError as e :
7779 pass
80+
81+ # The source is encoded before it is parsed, so a lone surrogate has to be
82+ # reported rather than assumed away.
83+ with assert_raises (UnicodeEncodeError ):
84+ eval (chr (0xD800 ))
Original file line number Diff line number Diff line change 11import builtins
2+ import itertools
23import pickle
34import platform
45import sys
@@ -393,3 +394,19 @@ class SubError(MyError):
393394 assert err .exceptions [0 ].args == ("x" ,)
394395else :
395396 assert False , "except* handler did not run"
397+
398+ # The exceptions argument is a sequence, so an arbitrary iterable must be
399+ # rejected rather than drained.
400+ try :
401+ ExceptionGroup ("m" , itertools .count ())
402+ except TypeError :
403+ pass
404+ else :
405+ assert False , "ExceptionGroup accepted an unbounded iterable"
406+
407+ # ImportError.__reduce__ has to cope with the exception carrying no args.
408+ assert pickle .loads (pickle .dumps (ImportError ())).args == ()
409+ restored = pickle .loads (pickle .dumps (ImportError ("m" , name = "n" , path = "p" )))
410+ assert restored .args == ("m" ,)
411+ assert restored .name == "n"
412+ assert restored .path == "p"
Original file line number Diff line number Diff line change 1+ from testutils import assert_raises
2+
13exec ("def square(x):\n return x * x\n " )
24assert 16 == square (4 ) # noqa: F821
35
@@ -71,3 +73,8 @@ def f():
7173
7274
7375f ()
76+
77+ # The source is encoded before it is parsed, so a lone surrogate has to be
78+ # reported rather than assumed away.
79+ with assert_raises (UnicodeEncodeError ):
80+ exec (chr (0xD800 ))
Original file line number Diff line number Diff line change 1+ import sys
2+
13from testutils import assert_raises
24
35
@@ -28,3 +30,19 @@ def __hash__(self):
2830
2931with assert_raises (TypeError ):
3032 hash ([])
33+
34+ # Hashing a deeply nested tuple must not run off the native stack: the hash
35+ # slot dispatch is what recurses, so that is where the depth is checked.
36+
37+ if sys .implementation .name == "rustpython" :
38+ # CPython, which also runs this snippet, survives this depth unguarded.
39+ deep_tuple = ()
40+ for _ in range (sys .getrecursionlimit () * 2 ):
41+ deep_tuple = (deep_tuple ,)
42+ with assert_raises (RecursionError ):
43+ hash (deep_tuple )
44+ # a dict key and a set member are hashed on insertion, same dispatch
45+ with assert_raises (RecursionError ):
46+ {deep_tuple : 1 }
47+ with assert_raises (RecursionError ):
48+ {deep_tuple }
Original file line number Diff line number Diff line change 1+ import sys
2+
13from testutils import assert_raises
24
35x = [1 , 2 , 3 ]
@@ -923,3 +925,8 @@ def __eq__(self, other):
923925list1 = rewrite_list_eq ([poc ()])
924926list1 .remove (list1 )
925927assert list1 == []
928+
929+ # The repeat count is multiplied by the element size; a count that overflows
930+ # that product must raise instead of wrapping into a short allocation.
931+ with assert_raises (MemoryError ):
932+ [1 ] * sys .maxsize
Original file line number Diff line number Diff line change 1+ import sys
2+
13from testutils import assert_raises
24
35assert (1 , 2 ) == (1 , 2 )
@@ -93,3 +95,8 @@ def __eq__(self, x):
9395assert (float ("inf" ), float ("inf" )) >= (float ("inf" ), float ("inf" ))
9496assert not (float ("inf" ), float ("inf" )) < (float ("inf" ), float ("inf" ))
9597assert not (float ("inf" ), float ("inf" )) > (float ("inf" ), float ("inf" ))
98+
99+ # The repeat count is multiplied by the element size; a count that overflows
100+ # that product must raise instead of wrapping into a short allocation.
101+ with assert_raises (MemoryError ):
102+ (1 ,) * sys .maxsize
You can’t perform that action at this time.
0 commit comments