mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-37115: Support annotations in positional-only arguments (GH-13698)
This commit is contained in:
parent
2f58a84104
commit
a0c01bf136
3 changed files with 57 additions and 4 deletions
|
@ -620,14 +620,22 @@ class GrammarTests(unittest.TestCase):
|
|||
self.assertEqual(f.__annotations__, {'return': list})
|
||||
def f(x: int): pass
|
||||
self.assertEqual(f.__annotations__, {'x': int})
|
||||
def f(x: int, /): pass
|
||||
self.assertEqual(f.__annotations__, {'x': int})
|
||||
def f(x: int = 34, /): pass
|
||||
self.assertEqual(f.__annotations__, {'x': int})
|
||||
def f(*x: str): pass
|
||||
self.assertEqual(f.__annotations__, {'x': str})
|
||||
def f(**x: float): pass
|
||||
self.assertEqual(f.__annotations__, {'x': float})
|
||||
def f(x, y: 1+2): pass
|
||||
self.assertEqual(f.__annotations__, {'y': 3})
|
||||
def f(x, y: 1+2, /): pass
|
||||
self.assertEqual(f.__annotations__, {'y': 3})
|
||||
def f(a, b: 1, c: 2, d): pass
|
||||
self.assertEqual(f.__annotations__, {'b': 1, 'c': 2})
|
||||
def f(a, b: 1, /, c: 2, d): pass
|
||||
self.assertEqual(f.__annotations__, {'b': 1, 'c': 2})
|
||||
def f(a, b: 1, c: 2, d, e: 3 = 4, f=5, *g: 6): pass
|
||||
self.assertEqual(f.__annotations__,
|
||||
{'b': 1, 'c': 2, 'e': 3, 'g': 6})
|
||||
|
@ -636,6 +644,11 @@ class GrammarTests(unittest.TestCase):
|
|||
self.assertEqual(f.__annotations__,
|
||||
{'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9,
|
||||
'k': 11, 'return': 12})
|
||||
def f(a, b: 1, c: 2, d, e: 3 = 4, f: int = 5, /, *g: 6, h: 7, i=8, j: 9 = 10,
|
||||
**k: 11) -> 12: pass
|
||||
self.assertEqual(f.__annotations__,
|
||||
{'b': 1, 'c': 2, 'e': 3, 'f': int, 'g': 6, 'h': 7, 'j': 9,
|
||||
'k': 11, 'return': 12})
|
||||
# Check for issue #20625 -- annotations mangling
|
||||
class Spam:
|
||||
def f(self, *, __kw: 1):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue