summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/tests
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-09-09 03:50:03 (GMT)
committerYury Selivanov <yury@magic.io>2016-09-09 03:50:03 (GMT)
commitf8cb8a16a344ab208fd46876c4b63604987347b8 (patch)
treec44caa48291401d1e1e388004d2762513ac88c93 /Lib/lib2to3/tests
parent09ad17810c38d1aaae02de69084dd2a8ad9f5cdb (diff)
downloadcpython-f8cb8a16a344ab208fd46876c4b63604987347b8.zip
cpython-f8cb8a16a344ab208fd46876c4b63604987347b8.tar.gz
cpython-f8cb8a16a344ab208fd46876c4b63604987347b8.tar.bz2
Issue #27985: Implement PEP 526 -- Syntax for Variable Annotations.
Patch by Ivan Levkivskyi.
Diffstat (limited to 'Lib/lib2to3/tests')
-rw-r--r--Lib/lib2to3/tests/test_parser.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
index 9adb031..b378163 100644
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -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 = """