summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3')
-rw-r--r--Lib/lib2to3/Grammar.txt7
-rw-r--r--Lib/lib2to3/fixer_util.py2
-rw-r--r--Lib/lib2to3/fixes/fix_dict.py3
-rw-r--r--Lib/lib2to3/fixes/fix_exec.py1
-rw-r--r--Lib/lib2to3/fixes/fix_filter.py1
-rw-r--r--Lib/lib2to3/fixes/fix_has_key.py1
-rw-r--r--Lib/lib2to3/fixes/fix_metaclass.py2
-rw-r--r--Lib/lib2to3/fixes/fix_nonzero.py2
-rw-r--r--Lib/lib2to3/fixes/fix_print.py2
-rw-r--r--Lib/lib2to3/fixes/fix_types.py3
-rw-r--r--Lib/lib2to3/fixes/fix_urllib.py1
-rw-r--r--Lib/lib2to3/refactor.py3
-rw-r--r--Lib/lib2to3/tests/data/py3_test_grammar.py2
-rw-r--r--Lib/lib2to3/tests/support.py2
-rw-r--r--Lib/lib2to3/tests/test_all_fixers.py1
-rw-r--r--Lib/lib2to3/tests/test_fixers.py7
-rw-r--r--Lib/lib2to3/tests/test_parser.py50
-rw-r--r--Lib/lib2to3/tests/test_pytree.py5
-rw-r--r--Lib/lib2to3/tests/test_refactor.py6
-rw-r--r--Lib/lib2to3/tests/test_util.py3
20 files changed, 64 insertions, 40 deletions
diff --git a/Lib/lib2to3/Grammar.txt b/Lib/lib2to3/Grammar.txt
index 60503dd..2abd5ee 100644
--- a/Lib/lib2to3/Grammar.txt
+++ b/Lib/lib2to3/Grammar.txt
@@ -54,12 +54,13 @@ stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | exec_stmt | assert_stmt)
-expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
+expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*)
+annassign: ':' test ['=' test]
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
-# For normal assignments, additional restrictions enforced by the interpreter
+# For normal and annotated assignments, additional restrictions enforced by the interpreter
print_stmt: 'print' ( [ test (',' test)* [','] ] |
'>>' test [ (',' test)+ [','] ] )
del_stmt: 'del' exprlist
@@ -160,7 +161,7 @@ argument: ( test [comp_for] |
star_expr )
comp_iter: comp_for | comp_if
-comp_for: 'for' exprlist 'in' testlist_safe [comp_iter]
+comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [comp_iter]
comp_if: 'if' old_test [comp_iter]
testlist1: test (',' test)*
diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py
index 44502bf..babe6cb 100644
--- a/Lib/lib2to3/fixer_util.py
+++ b/Lib/lib2to3/fixer_util.py
@@ -1,8 +1,6 @@
"""Utility functions, node construction macros, etc."""
# Author: Collin Winter
-from itertools import islice
-
# Local imports
from .pgen2 import token
from .pytree import Leaf, Node
diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py
index 963f952..d3655c9 100644
--- a/Lib/lib2to3/fixes/fix_dict.py
+++ b/Lib/lib2to3/fixes/fix_dict.py
@@ -30,9 +30,8 @@ as an argument to a function that introspects the argument).
# Local imports
from .. import pytree
from .. import patcomp
-from ..pgen2 import token
from .. import fixer_base
-from ..fixer_util import Name, Call, LParen, RParen, ArgList, Dot
+from ..fixer_util import Name, Call, Dot
from .. import fixer_util
diff --git a/Lib/lib2to3/fixes/fix_exec.py b/Lib/lib2to3/fixes/fix_exec.py
index 2c9b72d..ab921ee 100644
--- a/Lib/lib2to3/fixes/fix_exec.py
+++ b/Lib/lib2to3/fixes/fix_exec.py
@@ -10,7 +10,6 @@ exec code in ns1, ns2 -> exec(code, ns1, ns2)
"""
# Local imports
-from .. import pytree
from .. import fixer_base
from ..fixer_util import Comma, Name, Call
diff --git a/Lib/lib2to3/fixes/fix_filter.py b/Lib/lib2to3/fixes/fix_filter.py
index 391889f..bb6718c 100644
--- a/Lib/lib2to3/fixes/fix_filter.py
+++ b/Lib/lib2to3/fixes/fix_filter.py
@@ -14,7 +14,6 @@ Python 2.6 figure it out.
"""
# Local imports
-from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, Call, ListComp, in_special_context
diff --git a/Lib/lib2to3/fixes/fix_has_key.py b/Lib/lib2to3/fixes/fix_has_key.py
index 18c560f..439708c 100644
--- a/Lib/lib2to3/fixes/fix_has_key.py
+++ b/Lib/lib2to3/fixes/fix_has_key.py
@@ -31,7 +31,6 @@ CAVEATS:
# Local imports
from .. import pytree
-from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, parenthesize
diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py
index 46c7aaf..8e34463 100644
--- a/Lib/lib2to3/fixes/fix_metaclass.py
+++ b/Lib/lib2to3/fixes/fix_metaclass.py
@@ -20,7 +20,7 @@
# Local imports
from .. import fixer_base
from ..pygram import token
-from ..fixer_util import Name, syms, Node, Leaf
+from ..fixer_util import syms, Node, Leaf
def has_metaclass(parent):
diff --git a/Lib/lib2to3/fixes/fix_nonzero.py b/Lib/lib2to3/fixes/fix_nonzero.py
index ad91a29..c229596 100644
--- a/Lib/lib2to3/fixes/fix_nonzero.py
+++ b/Lib/lib2to3/fixes/fix_nonzero.py
@@ -3,7 +3,7 @@
# Local imports
from .. import fixer_base
-from ..fixer_util import Name, syms
+from ..fixer_util import Name
class FixNonzero(fixer_base.BaseFix):
BM_compatible = True
diff --git a/Lib/lib2to3/fixes/fix_print.py b/Lib/lib2to3/fixes/fix_print.py
index a1fe2f5..8780322 100644
--- a/Lib/lib2to3/fixes/fix_print.py
+++ b/Lib/lib2to3/fixes/fix_print.py
@@ -18,7 +18,7 @@ from .. import patcomp
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
-from ..fixer_util import Name, Call, Comma, String, is_tuple
+from ..fixer_util import Name, Call, Comma, String
parend_expr = patcomp.compile_pattern(
diff --git a/Lib/lib2to3/fixes/fix_types.py b/Lib/lib2to3/fixes/fix_types.py
index db34104..67bf51f 100644
--- a/Lib/lib2to3/fixes/fix_types.py
+++ b/Lib/lib2to3/fixes/fix_types.py
@@ -20,7 +20,6 @@ There should be another fixer that handles at least the following constants:
"""
# Local imports
-from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name
@@ -42,7 +41,7 @@ _TYPE_MAPPING = {
'NotImplementedType' : 'type(NotImplemented)',
'SliceType' : 'slice',
'StringType': 'bytes', # XXX ?
- 'StringTypes' : 'str', # XXX ?
+ 'StringTypes' : '(str,)', # XXX ?
'TupleType': 'tuple',
'TypeType' : 'type',
'UnicodeType': 'str',
diff --git a/Lib/lib2to3/fixes/fix_urllib.py b/Lib/lib2to3/fixes/fix_urllib.py
index 1481cd9..5a36049 100644
--- a/Lib/lib2to3/fixes/fix_urllib.py
+++ b/Lib/lib2to3/fixes/fix_urllib.py
@@ -6,7 +6,6 @@
# Local imports
from lib2to3.fixes.fix_imports import alternates, FixImports
-from lib2to3 import fixer_base
from lib2to3.fixer_util import (Name, Comma, FromImport, Newline,
find_indentation, Node, syms)
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 0728083..c5a1aa2 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -8,8 +8,6 @@ recursively descend down directories. Imported as a module, this
provides infrastructure to write your own refactoring tool.
"""
-from __future__ import with_statement
-
__author__ = "Guido van Rossum <guido@python.org>"
@@ -26,7 +24,6 @@ from itertools import chain
from .pgen2 import driver, tokenize, token
from .fixer_util import find_root
from . import pytree, pygram
-from . import btm_utils as bu
from . import btm_matcher as bm
diff --git a/Lib/lib2to3/tests/data/py3_test_grammar.py b/Lib/lib2to3/tests/data/py3_test_grammar.py
index c0bf7f2..cf31a54 100644
--- a/Lib/lib2to3/tests/data/py3_test_grammar.py
+++ b/Lib/lib2to3/tests/data/py3_test_grammar.py
@@ -319,7 +319,7 @@ class GrammarTests(unittest.TestCase):
def f(x) -> list: pass
self.assertEquals(f.__annotations__, {'return': list})
- # test MAKE_CLOSURE with a variety of oparg's
+ # test closures with a variety of oparg's
closure = 1
def f(): return closure
def f(x=1): return closure
diff --git a/Lib/lib2to3/tests/support.py b/Lib/lib2to3/tests/support.py
index 0897177..ae7cfe8 100644
--- a/Lib/lib2to3/tests/support.py
+++ b/Lib/lib2to3/tests/support.py
@@ -3,10 +3,8 @@
# Python imports
import unittest
-import sys
import os
import os.path
-import re
from textwrap import dedent
# Local imports
diff --git a/Lib/lib2to3/tests/test_all_fixers.py b/Lib/lib2to3/tests/test_all_fixers.py
index 15079fe..c0507cf 100644
--- a/Lib/lib2to3/tests/test_all_fixers.py
+++ b/Lib/lib2to3/tests/test_all_fixers.py
@@ -10,7 +10,6 @@ import unittest
import test.support
# Local imports
-from lib2to3 import refactor
from . import support
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
index 640dcef..b3f2680 100644
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -2,12 +2,11 @@
# Python imports
import os
-import unittest
from itertools import chain
from operator import itemgetter
# Local imports
-from lib2to3 import pygram, pytree, refactor, fixer_util
+from lib2to3 import pygram, fixer_util
from lib2to3.tests import support
@@ -3234,6 +3233,10 @@ class Test_types(FixerTestCase):
a = """type(None)"""
self.check(b, a)
+ b = "types.StringTypes"
+ a = "(str,)"
+ self.check(b, a)
+
class Test_idioms(FixerTestCase):
fixer = "idioms"
diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
index e4a0194..9a969e8 100644
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -8,7 +8,7 @@ test_grammar.py files from both Python 2 and Python 3.
# Testing imports
from . import support
-from .support import driver, test_dir
+from .support import driver
from test.support import verbose
# Python imports
@@ -134,6 +134,24 @@ class TestAsyncAwait(GrammarTest):
""")
self.validate("""async def foo():
+ [i async for i in b]
+ """)
+
+ self.validate("""async def foo():
+ {i for i in b
+ async for i in a if await i
+ for b in i}
+ """)
+
+ self.validate("""async def foo():
+ [await i for i in b if await c]
+ """)
+
+ self.validate("""async def foo():
+ [ i for i in b if c]
+ """)
+
+ self.validate("""async def foo():
def foo(): pass
@@ -272,6 +290,36 @@ class TestFunctionAnnotations(GrammarTest):
self.validate(s)
+# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.test_var_annot
+class TestVarAnnotations(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 = """
diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/lib2to3/tests/test_pytree.py
index 4d585a8..177126d 100644
--- a/Lib/lib2to3/tests/test_pytree.py
+++ b/Lib/lib2to3/tests/test_pytree.py
@@ -9,11 +9,6 @@ more helpful than printing of (the first line of) the docstring,
especially when debugging a test.
"""
-from __future__ import with_statement
-
-import sys
-import warnings
-
# Testing imports
from . import support
diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/lib2to3/tests/test_refactor.py
index 8563001..e9bae5e 100644
--- a/Lib/lib2to3/tests/test_refactor.py
+++ b/Lib/lib2to3/tests/test_refactor.py
@@ -2,24 +2,18 @@
Unit tests for refactor.py.
"""
-from __future__ import with_statement
-
import sys
import os
import codecs
-import operator
import io
import re
import tempfile
import shutil
import unittest
-import warnings
from lib2to3 import refactor, pygram, fixer_base
from lib2to3.pgen2 import token
-from . import support
-
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers")
diff --git a/Lib/lib2to3/tests/test_util.py b/Lib/lib2to3/tests/test_util.py
index d2be82c..c6c6139 100644
--- a/Lib/lib2to3/tests/test_util.py
+++ b/Lib/lib2to3/tests/test_util.py
@@ -3,9 +3,6 @@
# Testing imports
from . import support
-# Python imports
-import os.path
-
# Local imports
from lib2to3.pytree import Node, Leaf
from lib2to3 import fixer_util