Skip to content

Update to typed-ast 1.0.0 #2857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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