Issue #27985: Implement PEP 526 -- Syntax for Variable Annotations.

Patch by Ivan Levkivskyi.
This commit is contained in:
Yury Selivanov 2016-09-08 20:50:03 -07:00
parent 09ad17810c
commit f8cb8a16a3
45 changed files with 3242 additions and 1308 deletions

View file

@ -237,6 +237,36 @@ class TestFunctionAnnotations(GrammarTest):
self.validate(s)
# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.test_var_annot
class TestFunctionAnnotations(GrammarTest):
def test_1(self):
self.validate("var1: int = 5")
def test_2(self):
self.validate("var2: [int, str]")
def test_3(self):
self.validate("def f():\n"
" st: str = 'Hello'\n"
" a.b: int = (1, 2)\n"
" return st\n")
def test_4(self):
self.validate("def fbad():\n"
" x: int\n"
" print(x)\n")
def test_5(self):
self.validate("class C:\n"
" x: int\n"
" s: str = 'attr'\n"
" z = 2\n"
" def __init__(self, x):\n"
" self.x: int = x\n")
def test_6(self):
self.validate("lst: List[int] = []")
class TestExcept(GrammarTest):
def test_new(self):
s = """