Skip to content

Commit 3cc5201

Browse files
ddfishergvanrossum
authored andcommitted
Update to typed-ast 1.0.0 (#2857)
1 parent 35a986a commit 3cc5201

9 files changed

+172
-169
lines changed

mypy/fastparse.py

Lines changed: 151 additions & 152 deletions
Large diffs are not rendered by default.

mypy/fastparse2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
try:
4646
from typed_ast import ast27
47-
from typed_ast import ast35
47+
from typed_ast import ast3 # type: ignore # typeshed PR #931
4848
except ImportError:
4949
if sys.version_info.minor > 2:
5050
print('You must install the typed_ast package before you can run mypy'
@@ -291,11 +291,11 @@ def visit_FunctionDef(self, n: ast27.FunctionDef) -> Statement:
291291
return_type = None
292292
elif n.type_comment is not None and len(n.type_comment) > 0:
293293
try:
294-
func_type_ast = ast35.parse(n.type_comment, '<func_type>', 'func_type')
295-
assert isinstance(func_type_ast, ast35.FunctionType)
294+
func_type_ast = ast3.parse(n.type_comment, '<func_type>', 'func_type')
295+
assert isinstance(func_type_ast, ast3.FunctionType)
296296
# for ellipsis arg
297297
if (len(func_type_ast.argtypes) == 1 and
298-
isinstance(func_type_ast.argtypes[0], ast35.Ellipsis)):
298+
isinstance(func_type_ast.argtypes[0], ast3.Ellipsis)):
299299
arg_types = [a.type_annotation if a.type_annotation is not None else AnyType()
300300
for a in args]
301301
else:

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ def analyze_lvalue(self, lval: Lvalue, nested: bool = False,
14971497
isinstance(lval, ListExpr)):
14981498
items = lval.items
14991499
if len(items) == 0 and isinstance(lval, TupleExpr):
1500-
self.fail("Can't assign to ()", lval)
1500+
self.fail("can't assign to ()", lval)
15011501
self.analyze_tuple_or_list_lvalue(lval, add_global, explicit_type)
15021502
elif isinstance(lval, StarExpr):
15031503
if nested:

mypy/test/testcheck.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
import time
88
import typed_ast
9-
import typed_ast.ast35
109

1110
from typing import Dict, List, Optional, Set, Tuple
1211

@@ -73,16 +72,12 @@
7372
'check-expressions.test',
7473
'check-generic-subtyping.test',
7574
'check-varargs.test',
75+
'check-newsyntax.test',
76+
'check-underscores.test',
7677
]
7778

7879
files.extend(fast_parser_files)
7980

80-
if 'annotation' in typed_ast.ast35.Assign._fields:
81-
fast_parser_files.append('check-newsyntax.test')
82-
83-
if 'contains_underscores' in typed_ast.ast35.Num._fields:
84-
fast_parser_files.append('check-underscores.test')
85-
8681

8782
class TypeCheckSuite(DataSuite):
8883
def __init__(self, *, update_data: bool = False) -> None:

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ show_missing = true
5656
# Then run "python3 setup.py bdist_wheel" to build a wheel file
5757
# (and then upload that to PyPI).
5858
requires-dist =
59-
typed-ast >= 0.6.3, < 0.7.0
59+
typed-ast >= 1.0.0, < 1.1.0
6060
typing >= 3.5.3; python_version < "3.5"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def run(self):
100100
# "pip3 install git+git://github.com/python/mypy.git"
101101
# (as suggested by README.md).
102102
install_requires = []
103-
install_requires.append('typed-ast >= 0.6.3, < 0.7.0')
103+
install_requires.append('typed-ast >= 1.0.0, < 1.1.0')
104104
if sys.version_info < (3, 5):
105105
install_requires.append('typing >= 3.5.3')
106106

test-data/unit/check-newsyntax.test

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[case testNewSyntaxRequire36]
22
# flags: --fast-parser --python-version 3.5
3-
x: int = 5 # E: Variable annotation syntax is only supported in Python 3.6, use type comment instead
3+
x: int = 5 # E: Variable annotation syntax is only supported in Python 3.6 and greater
44
[out]
55

66
[case testNewSyntaxSyntaxError]
@@ -98,3 +98,12 @@ main:4: error: Unexpected type declaration
9898
main:4: error: Unsupported target for indexed assignment
9999
main:5: error: Type cannot be declared in assignment to non-self attribute
100100
main:5: error: "str" has no attribute "x"
101+
102+
[case testNewSyntaxFstringError]
103+
# flags: --fast-parser --python-version 3.5
104+
f'' # E: Format strings are only supported in Python 3.6 and greater
105+
106+
[case testNewSyntaxAsyncComprehensionError]
107+
# flags: --fast-parser --python-version 3.5
108+
async def f():
109+
results = [i async for i in aiter() if i % 2] # E: Async comprehensions are only supported in Python 3.6 and greater

test-data/unit/check-underscores.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[case testUnderscoresRequire36]
22
# flags: --fast-parser --python-version 3.5
3-
x = 1000_000 # E: Underscores in numeric literals are only supported in Python 3.6
3+
x = 1000_000 # E: Underscores in numeric literals are only supported in Python 3.6 and greater
44
[out]
55

66
[case testUnderscoresSyntaxError]

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ flake8
22
flake8-bugbear; python_version >= '3.5'
33
flake8-pyi; python_version >= '3.5'
44
lxml; sys_platform != 'win32' or python_version == '3.5' or python_version == '3.6'
5-
typed-ast>=0.6.3,<0.7.0; sys_platform != 'win32' or python_version >= '3.5'
5+
typed-ast>=1.0.0,<1.1.0; sys_platform != 'win32' or python_version >= '3.5'
66
pytest>=2.8
77
pytest-xdist>=1.13
88
pytest-cov>=2.4.0

0 commit comments

Comments
 (0)