Skip to content

Commit

Permalink
Update to typed-ast 1.0.0 (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddfisher authored and gvanrossum committed Feb 13, 2017
1 parent 35a986a commit 3cc5201
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 169 deletions.
303 changes: 151 additions & 152 deletions mypy/fastparse.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions mypy/fastparse2.py
Expand Up @@ -44,7 +44,7 @@

try:
from typed_ast import ast27
from typed_ast import ast35
from typed_ast import ast3 # type: ignore # typeshed PR #931
except ImportError:
if sys.version_info.minor > 2:
print('You must install the typed_ast package before you can run mypy'
Expand Down Expand Up @@ -291,11 +291,11 @@ def visit_FunctionDef(self, n: ast27.FunctionDef) -> Statement:
return_type = None
elif n.type_comment is not None and len(n.type_comment) > 0:
try:
func_type_ast = ast35.parse(n.type_comment, '<func_type>', 'func_type')
assert isinstance(func_type_ast, ast35.FunctionType)
func_type_ast = ast3.parse(n.type_comment, '<func_type>', 'func_type')
assert isinstance(func_type_ast, ast3.FunctionType)
# for ellipsis arg
if (len(func_type_ast.argtypes) == 1 and
isinstance(func_type_ast.argtypes[0], ast35.Ellipsis)):
isinstance(func_type_ast.argtypes[0], ast3.Ellipsis)):
arg_types = [a.type_annotation if a.type_annotation is not None else AnyType()
for a in args]
else:
Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Expand Up @@ -1497,7 +1497,7 @@ def analyze_lvalue(self, lval: Lvalue, nested: bool = False,
isinstance(lval, ListExpr)):
items = lval.items
if len(items) == 0 and isinstance(lval, TupleExpr):
self.fail("Can't assign to ()", lval)
self.fail("can't assign to ()", lval)
self.analyze_tuple_or_list_lvalue(lval, add_global, explicit_type)
elif isinstance(lval, StarExpr):
if nested:
Expand Down
9 changes: 2 additions & 7 deletions mypy/test/testcheck.py
Expand Up @@ -6,7 +6,6 @@
import sys
import time
import typed_ast
import typed_ast.ast35

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

Expand Down Expand Up @@ -73,16 +72,12 @@
'check-expressions.test',
'check-generic-subtyping.test',
'check-varargs.test',
'check-newsyntax.test',
'check-underscores.test',
]

files.extend(fast_parser_files)

if 'annotation' in typed_ast.ast35.Assign._fields:
fast_parser_files.append('check-newsyntax.test')

if 'contains_underscores' in typed_ast.ast35.Num._fields:
fast_parser_files.append('check-underscores.test')


class TypeCheckSuite(DataSuite):
def __init__(self, *, update_data: bool = False) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -56,5 +56,5 @@ show_missing = true
# Then run "python3 setup.py bdist_wheel" to build a wheel file
# (and then upload that to PyPI).
requires-dist =
typed-ast >= 0.6.3, < 0.7.0
typed-ast >= 1.0.0, < 1.1.0
typing >= 3.5.3; python_version < "3.5"
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -100,7 +100,7 @@ def run(self):
# "pip3 install git+git://github.com/python/mypy.git"
# (as suggested by README.md).
install_requires = []
install_requires.append('typed-ast >= 0.6.3, < 0.7.0')
install_requires.append('typed-ast >= 1.0.0, < 1.1.0')
if sys.version_info < (3, 5):
install_requires.append('typing >= 3.5.3')

Expand Down
11 changes: 10 additions & 1 deletion test-data/unit/check-newsyntax.test
@@ -1,6 +1,6 @@
[case testNewSyntaxRequire36]
# flags: --fast-parser --python-version 3.5
x: int = 5 # E: Variable annotation syntax is only supported in Python 3.6, use type comment instead
x: int = 5 # E: Variable annotation syntax is only supported in Python 3.6 and greater
[out]

[case testNewSyntaxSyntaxError]
Expand Down Expand Up @@ -98,3 +98,12 @@ main:4: error: Unexpected type declaration
main:4: error: Unsupported target for indexed assignment
main:5: error: Type cannot be declared in assignment to non-self attribute
main:5: error: "str" has no attribute "x"

[case testNewSyntaxFstringError]
# flags: --fast-parser --python-version 3.5
f'' # E: Format strings are only supported in Python 3.6 and greater

[case testNewSyntaxAsyncComprehensionError]
# flags: --fast-parser --python-version 3.5
async def f():
results = [i async for i in aiter() if i % 2] # E: Async comprehensions are only supported in Python 3.6 and greater
2 changes: 1 addition & 1 deletion test-data/unit/check-underscores.test
@@ -1,6 +1,6 @@
[case testUnderscoresRequire36]
# flags: --fast-parser --python-version 3.5
x = 1000_000 # E: Underscores in numeric literals are only supported in Python 3.6
x = 1000_000 # E: Underscores in numeric literals are only supported in Python 3.6 and greater
[out]

[case testUnderscoresSyntaxError]
Expand Down
2 changes: 1 addition & 1 deletion test-requirements.txt
Expand Up @@ -2,7 +2,7 @@ flake8
flake8-bugbear; python_version >= '3.5'
flake8-pyi; python_version >= '3.5'
lxml; sys_platform != 'win32' or python_version == '3.5' or python_version == '3.6'
typed-ast>=0.6.3,<0.7.0; sys_platform != 'win32' or python_version >= '3.5'
typed-ast>=1.0.0,<1.1.0; sys_platform != 'win32' or python_version >= '3.5'
pytest>=2.8
pytest-xdist>=1.13
pytest-cov>=2.4.0
Expand Down

0 comments on commit 3cc5201

Please sign in to comment.