diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_compile.py | 13 | ||||
-rw-r--r-- | Lib/test/test_grammar.py | 7 | ||||
-rw-r--r-- | Lib/test/test_peepholer.py | 8 |
3 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 022f7c0..d5fda13 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -393,6 +393,19 @@ if 1: del d[..., ...] self.assertEqual((Ellipsis, Ellipsis) in d, False) + def test_annotation_limit(self): + # 16 bits are available for # of annotations, and the + # tuple of annotations names is counted, hence 65534 + # is the max. Ensure the result of too many annotations is a + # SyntaxError. + s = "def f((%s)): pass" + s %= ', '.join('a%d:%d' % (i,i) for i in xrange(65535)) + self.assertRaises(SyntaxError, compile, s, '?', 'exec') + # Test that the max # of annotations compiles. + s = "def f((%s)): pass" + s %= ', '.join('a%d:%d' % (i,i) for i in xrange(65534)) + compile(s, '?', 'exec') + def test_main(): test_support.run_unittest(TestSpecifics) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index cb37021..1a14756 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -321,6 +321,13 @@ class GrammarTests(unittest.TestCase): self.assertEquals(f.__annotations__, {'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9, 'k': 11, 'return': 12}) + + # test MAKE_CLOSURE with a variety of oparg's + closure = 1 + def f(): return closure + def f(x=1): return closure + def f(*, k=1): return closure + def f() -> int: return closure def testLambdef(self): ### lambdef: 'lambda' [varargslist] ':' test diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index 213edd2..9ed814a 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -195,6 +195,14 @@ class TestTranforms(unittest.TestCase): # There should be one jump for the while loop. self.assertEqual(asm.split().count('JUMP_ABSOLUTE'), 1) self.assertEqual(asm.split().count('RETURN_VALUE'), 2) + + def test_make_function_doesnt_bail(self): + def f(): + def g()->1+1: + pass + return g + asm = disassemble(f) + self.assert_('BINARY_ADD' not in asm) def test_main(verbose=None): |