Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
249d70f
Implement Callable[[Arg('name', Type)], ret] syntax
sixolet Nov 11, 2016
7ecdcc1
General cleanup
sixolet Dec 24, 2016
066bd5e
Change tests back to match old behavior
sixolet Dec 24, 2016
213944b
lots of lint
sixolet Dec 24, 2016
0e19070
Oh god I am tired of writing parsers
sixolet Dec 25, 2016
3f2f617
Tighten fastparse a little
sixolet Dec 25, 2016
0b69630
make all tests pass now
sixolet Dec 25, 2016
f4ccf92
go back to master version of typeshed I guess
sixolet Dec 25, 2016
967bb5a
Meged master, but tests fail again now.
sixolet Apr 12, 2017
bb5134e
Tests all pass again after merge
sixolet Apr 18, 2017
d4a83e1
Merged master again
sixolet Apr 18, 2017
54a5da9
Big refactor. Wait until semanal to get arg kinds, switch order again…
sixolet Apr 20, 2017
e79c527
Change back to TypeList
sixolet Apr 20, 2017
52ffe5c
Cleanups. Preparing to split into two diffs maybe?
sixolet Apr 20, 2017
06416f7
update typeshed to master version
sixolet Apr 20, 2017
398fbad
more cleanups
sixolet Apr 20, 2017
2c9ce02
should not have changed these test files
sixolet Apr 20, 2017
51c6f56
Semanal needs to be a SyntheticTypeVisitor
sixolet Apr 20, 2017
5e679a3
Annot
sixolet Apr 20, 2017
0926fe9
Oops
sixolet Apr 20, 2017
288a8be
Add testing for exprtotype Arg constructors in wierd places
sixolet Apr 20, 2017
6e67ab2
Remove some ill-modified modifications to tests
sixolet Apr 20, 2017
97a859b
Merge master, no longer depend on other PR
sixolet Apr 20, 2017
1c7d4c6
Jukka comments
sixolet Apr 21, 2017
f153850
Synthetic types don't serialize
sixolet Apr 21, 2017
be954f5
Remove unused instance var
sixolet Apr 21, 2017
07ae917
Merge master
sixolet Apr 22, 2017
1b97362
Revert "Remove unused instance var"
sixolet Apr 22, 2017
552f49e
Accessing TypeList types directly is not required
sixolet Apr 22, 2017
f2e3663
Undo changes to this file they were not required
sixolet Apr 22, 2017
27e2a9d
lint
sixolet Apr 22, 2017
793a663
Merge master again
sixolet Apr 22, 2017
3d212b3
Merge master
sixolet May 1, 2017
0780149
Disallow CallableArgument in exprtotype outside a TypeList
sixolet May 1, 2017
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
Prev Previous commit
Next Next commit
lots of lint
  • Loading branch information
sixolet committed Dec 25, 2016
commit 213944be35c8ea9aecf1fa4143a3327854915e42
18 changes: 9 additions & 9 deletions mypy/exprtotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ARG_POS, ARG_NAMED,
)
from mypy.parsetype import parse_str_as_type, TypeParseError
from mypy.types import Type, UnboundType, ArgumentList, EllipsisType, AnyType
from mypy.types import Type, UnboundType, ArgumentList, EllipsisType, AnyType, Optional


class TypeTranslationError(Exception):
Expand Down Expand Up @@ -44,28 +44,28 @@ def expr_to_unanalyzed_type(expr: Expression) -> Type:
else:
raise TypeTranslationError()
elif isinstance(expr, ListExpr):
types = [] # type: List[Type]
names = [] # type: List[Optional[str]]
kinds = [] # type: List[int]
types = [] # type: List[Type]
names = [] # type: List[Optional[str]]
kinds = [] # type: List[int]
for it in expr.items:
if isinstance(expr_to_unanalyzed_type(it), CallExpr):
if isinstance(it, CallExpr):
if not isinstance(it.callee, NameExpr):
raise TypeTranslationError()
arg_const = it.callee.name
if arg_const == 'Arg':
if len(it.args) > 0:
name = it.args[0]
if not isinstance(name, StrLit):
arg_name = it.args[0]
if not isinstance(arg_name, StrExpr):
raise TypeTranslationError()
names.append(name.parsed())
names.append(arg_name.value)
else:
names.append(None)

if len(it.args) > 1:
typ = it.args[1]
types.append(expr_to_unanalyzed_type(typ))
else:
types.append(AnyType)
types.append(AnyType())

if len(it.args) > 2:
kinds.append(ARG_NAMED)
Expand Down
4 changes: 2 additions & 2 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,8 @@ def visit_Ellipsis(self, n: ast35.Ellipsis) -> Type:
def visit_List(self, n: ast35.List) -> Type:
return ArgumentList(
self.translate_expr_list(n.elts),
[None]*len(n.elts),
[0]*len(n.elts),
[None] * len(n.elts),
[0] * len(n.elts),
line=self.line)


Expand Down
2 changes: 1 addition & 1 deletion mypy/fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def visit_typeddict_type(self, tdt: TypedDictType) -> None:
tdt.fallback.accept(self)

def visit_type_list(self, tl: ArgumentList) -> None:
for t in tl.items:
for t in tl.types:
t.accept(self)

def visit_type_var(self, tvt: TypeVarType) -> None:
Expand Down
2 changes: 1 addition & 1 deletion mypy/indirection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def visit_unbound_type(self, t: types.UnboundType) -> Set[str]:
return self._visit(*t.args)

def visit_type_list(self, t: types.ArgumentList) -> Set[str]:
return self._visit(*t.items)
return self._visit(*t.types)

def visit_error_type(self, t: types.ErrorType) -> Set[str]:
return set()
Expand Down
4 changes: 2 additions & 2 deletions mypy/meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from mypy.join import is_similar_callables, combine_similar_callables, join_type_list
from mypy.types import (
Type, AnyType, TypeVisitor, UnboundType, Void, ErrorType, NoneTyp, TypeVarType,
Instance, CallableType, TupleType, TypedDictType, ErasedType, ArgumentList, UnionType, PartialType,
DeletedType, UninhabitedType, TypeType
Instance, CallableType, TupleType, TypedDictType, ErasedType, ArgumentList, UnionType,
PartialType, DeletedType, UninhabitedType, TypeType
)
from mypy.subtypes import is_equivalent, is_subtype

Expand Down
28 changes: 16 additions & 12 deletions mypy/parsetype.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""Type parser"""

from typing import List, Tuple, Union, Optional
from typing import List, Tuple, Union, Optional, TypeVar, cast

import typing

from mypy.types import (
Type, UnboundType, TupleType, ArgumentList, CallableType, StarType,
EllipsisType, AnyType
)

from mypy.lex import Token, Name, StrLit, lex
from mypy import nodes

T = TypeVar('T', bound=Token)

none = Token('') # Empty token

Expand Down Expand Up @@ -110,16 +114,16 @@ def parse_argument_spec(self) -> Tuple[Type, Optional[str], int]:
# TODO: Doesn't handle an explicit name of None yet.
if isinstance(current, Name) and nxt is not None and nxt.string == '(':
arg_const = self.expect_type(Name).string
name = None # type: Optional[str]
typ = AnyType # type: Type
name = None # type: Optional[str]
typ = AnyType(implicit=True) # type: Type
kind = {
'Arg': nodes.ARG_POS,
'DefaultArg': nodes.ARG_OPT,
'NamedArg': nodes.ARG_NAMED,
'DefaultNamedArg': nodes.ARG_NAMED_OPT,
'StarArg': nodes.ARG_STAR,
'KwArg': nodes.ARG_STAR2,
}[arg_const]
}[arg_const]
if arg_const in {'Arg', 'DefaultArg', 'NamedArg', 'DefaultNamedArg'}:
name, typ = self.parse_arg_args(read_name = True)
elif arg_const in {'StarArg', 'KwArg'}:
Expand All @@ -132,8 +136,8 @@ def parse_argument_spec(self) -> Tuple[Type, Optional[str], int]:

def parse_arg_args(self, *, read_name: bool) -> Tuple[Optional[str], Optional[Type]]:
self.expect('(')
name = None
typ = AnyType
name = None # type: Optional[str]
typ = AnyType(implicit=True) # type: Type
try:
if self.current_token_str() == ')':
return name, typ
Expand All @@ -154,15 +158,15 @@ def parse_arg_args(self, *, read_name: bool) -> Tuple[Optional[str], Optional[Ty
self.expect(',')
finally:
self.expect(')')

return name, typ

def parse_argument_list(self) -> ArgumentList:
"""Parse type list [t, ...]."""
lbracket = self.expect('[')
commas = [] # type: List[Token]
items = [] # type: List[Type]
names = [] # type: List[Optional[str]]
kinds = [] # type: List[int]
names = [] # type: List[Optional[str]]
kinds = [] # type: List[int]
while self.current_token_str() != ']':
t, name, kind = self.parse_argument_spec()
items.append(t)
Expand Down Expand Up @@ -227,18 +231,18 @@ def expect(self, string: str) -> Token:
else:
raise self.parse_error()

def expect_type(self, typ: type) -> Token:
def expect_type(self, typ: typing.Type[T]) -> T:
if isinstance(self.current_token(), typ):
self.ind += 1
return self.tok[self.ind - 1]
return cast(T, self.tok[self.ind - 1])
else:
raise self.parse_error()

def current_token(self) -> Token:
return self.tok[self.ind]

def next_token(self) -> Optional[Token]:
if self.ind + 1>= len(self.tok):
if self.ind + 1 >= len(self.tok):
return None
return self.tok[self.ind + 1]

Expand Down
3 changes: 2 additions & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from mypy.types import (
Type, AnyType, UnboundType, TypeVisitor, ErrorType, FormalArgument, Void, NoneTyp,
Instance, TypeVarType, CallableType, TupleType, TypedDictType, UnionType, Overloaded,
ErasedType, ArgumentList, PartialType, DeletedType, UninhabitedType, TypeType, is_named_instance
ErasedType, ArgumentList, PartialType, DeletedType, UninhabitedType, TypeType,
is_named_instance
)
import mypy.applytype
import mypy.constraints
Expand Down
11 changes: 5 additions & 6 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class ArgumentList(Type):
but a syntactic AST construct.
"""

items = None # type: List[Type]
types = None # type: List[Type]
names = None # type: List[Optional[str]]
kinds = None # type: List[int]

Expand All @@ -261,15 +261,14 @@ def serialize(self) -> JsonDict:
return {'.class': 'ArgumentList',
'items': [t.serialize() for t in self.types],
'names': self.names,
'kinds': self.kinds,
}
'kinds': self.kinds}

@classmethod
def deserialize(cls, data: JsonDict) -> 'ArgumentList':
assert data['.class'] == 'ArgumentList' or data['.class'] == 'TypeList'
types = [Type.deserialize(t) for t in data['items']]
names = cast(List[Optional[str]], data.get('names', [None]*len(types)))
kinds = cast(List[int], data.get('kinds', [ARG_POS]*len(types)))
names = cast(List[Optional[str]], data.get('names', [None] * len(types)))
kinds = cast(List[int], data.get('kinds', [ARG_POS] * len(types)))
return ArgumentList(
types=[Type.deserialize(t) for t in data['items']],
names=names,
Expand Down Expand Up @@ -1403,7 +1402,7 @@ def visit_unbound_type(self, t: UnboundType)-> str:
return s

def visit_type_list(self, t: ArgumentList) -> str:
return '<ArgumentList {}>'.format(self.list_str(t.items))
return '<ArgumentList {}>'.format(self.list_str(t.types))

def visit_error_type(self, t: ErrorType) -> str:
return '<ERROR>'
Expand Down