summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_grammar.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_grammar.py')
-rw-r--r--Lib/test/test_grammar.py48
1 files changed, 38 insertions, 10 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index f4a0478..34c550e 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -138,16 +138,22 @@ class GrammarTests(unittest.TestCase):
x = eval('1, 0 or 1')
def testFuncdef(self):
- ### 'def' NAME parameters ':' suite
- ### parameters: '(' [varargslist] ')'
- ### varargslist: (fpdef ['=' test] ',')*
- ### ('*' (NAME|',' fpdef ['=' test]) [',' ('**'|'*' '*') NAME]
- ### | ('**'|'*' '*') NAME)
- ### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
- ### fpdef: NAME | '(' fplist ')'
- ### fplist: fpdef (',' fpdef)* [',']
- ### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
- ### argument: [test '='] test # Really [keyword '='] test
+ ### [decorators] 'def' NAME parameters ['->' test] ':' suite
+ ### decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
+ ### decorators: decorator+
+ ### parameters: '(' [typedargslist] ')'
+ ### typedargslist: ((tfpdef ['=' test] ',')*
+ ### ('*' [tname] (',' tname ['=' test])* [',' '**' tname] | '**' tname)
+ ### | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
+ ### tname: NAME [':' test]
+ ### tfpdef: tname | '(' tfplist ')'
+ ### tfplist: tfpdef (',' tfpdef)* [',']
+ ### varargslist: ((vfpdef ['=' test] ',')*
+ ### ('*' [vname] (',' vname ['=' test])* [',' '**' vname] | '**' vname)
+ ### | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
+ ### vname: NAME
+ ### vfpdef: vname | '(' vfplist ')'
+ ### vfplist: vfpdef (',' vfpdef)* [',']
def f1(): pass
f1()
f1(*())
@@ -294,6 +300,28 @@ class GrammarTests(unittest.TestCase):
pos2key2dict(1,2,k2=100,tokwarg1=100,tokwarg2=200)
pos2key2dict(1,2,tokwarg1=100,tokwarg2=200, k2=100)
+ # argument annotation tests
+ def f(x) -> list: pass
+ self.assertEquals(f.func_annotations, {'return': list})
+ def f(x:int): pass
+ self.assertEquals(f.func_annotations, {'x': int})
+ def f(*x:str): pass
+ self.assertEquals(f.func_annotations, {'x': str})
+ def f(**x:float): pass
+ self.assertEquals(f.func_annotations, {'x': float})
+ def f(x, y:1+2): pass
+ self.assertEquals(f.func_annotations, {'y': 3})
+ def f(a, (b:1, c:2, d)): pass
+ self.assertEquals(f.func_annotations, {'b': 1, 'c': 2})
+ def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass
+ self.assertEquals(f.func_annotations,
+ {'b': 1, 'c': 2, 'e': 3, 'g': 6})
+ def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6, h:7, i=8, j:9=10,
+ **k:11) -> 12: pass
+ self.assertEquals(f.func_annotations,
+ {'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9,
+ 'k': 11, 'return': 12})
+
def testLambdef(self):
### lambdef: 'lambda' [varargslist] ':' test
l1 = lambda : 0