diff options
| author | Brandt Bucher <brandtbucher@gmail.com> | 2020-03-03 22:25:44 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-03 22:25:44 (GMT) |
| commit | be501ca2419a91546dea85ef4f36945545458589 (patch) | |
| tree | 75288eb978f78b97d2da5b2a052b9908531066f3 /Lib/test/test_grammar.py | |
| parent | 116fd4af7370706d0d99ac7c70541ef965672d4e (diff) | |
| download | cpython-be501ca2419a91546dea85ef4f36945545458589.zip cpython-be501ca2419a91546dea85ef4f36945545458589.tar.gz cpython-be501ca2419a91546dea85ef4f36945545458589.tar.bz2 | |
bpo-39702: Relax grammar restrictions on decorators (PEP 614) (GH-18570)
Diffstat (limited to 'Lib/test/test_grammar.py')
| -rw-r--r-- | Lib/test/test_grammar.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 2ed73e3..922a516 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -460,7 +460,7 @@ class GrammarTests(unittest.TestCase): def test_funcdef(self): ### [decorators] 'def' NAME parameters ['->' test] ':' suite - ### decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE + ### decorator: '@' namedexpr_test NEWLINE ### decorators: decorator+ ### parameters: '(' [typedargslist] ')' ### typedargslist: ((tfpdef ['=' test] ',')* @@ -666,6 +666,20 @@ class GrammarTests(unittest.TestCase): def f(x) -> list: pass self.assertEqual(f.__annotations__, {'return': list}) + # Test expressions as decorators (PEP 614): + @False or null + def f(x): pass + @d := null + def f(x): pass + @lambda f: null(f) + def f(x): pass + @[..., null, ...][1] + def f(x): pass + @null(null)(null) + def f(x): pass + @[null][0].__call__.__call__ + def f(x): pass + # test closures with a variety of opargs closure = 1 def f(): return closure @@ -1515,13 +1529,27 @@ class GrammarTests(unittest.TestCase): def meth2(self, arg): pass def meth3(self, a1, a2): pass - # decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE + # decorator: '@' namedexpr_test NEWLINE # decorators: decorator+ # decorated: decorators (classdef | funcdef) def class_decorator(x): return x @class_decorator class G: pass + # Test expressions as decorators (PEP 614): + @False or class_decorator + class H: pass + @d := class_decorator + class I: pass + @lambda c: class_decorator(c) + class J: pass + @[..., class_decorator, ...][1] + class K: pass + @class_decorator(class_decorator)(class_decorator) + class L: pass + @[class_decorator][0].__call__.__call__ + class M: pass + def test_dictcomps(self): # dictorsetmaker: ( (test ':' test (comp_for | # (',' test ':' test)* [','])) | |
