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
make all tests pass now
  • Loading branch information
sixolet committed Dec 25, 2016
commit 0b69630eeed92202aab23994e71e2bb5b210ff56
3 changes: 2 additions & 1 deletion mypy/exprtotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class TypeTranslationError(Exception):
"""Exception raised when an expression is not valid as a type."""


def _extract_str(expr: Expression) -> Optional[str]:
if isinstance(expr, NameExpr) and expr.name == 'None':
return None
Expand Down Expand Up @@ -66,7 +67,7 @@ def expr_to_unanalyzed_type(expr: Expression) -> Type:
except KeyError:
raise TypeTranslationError()
name = None
typ = AnyType(implicit=True)
typ = AnyType(implicit=True) # type: Type
star = arg_const in STAR_ARG_CONSTRUCTORS
for i, arg in enumerate(it.args):
if it.arg_names[i] is not None:
Expand Down
3 changes: 2 additions & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ def __init__(self, msg: str, lineno: int, offset: int) -> None:
class FastParserError(TypeCommentParseError):
pass

def _extract_str(arg: ast35.AST) -> Optional[str]:

def _extract_str(arg: ast35.expr) -> Optional[str]:
if isinstance(arg, ast35.Name) and arg.id == 'None':
return None
elif isinstance(arg, ast35.NameConstant) and arg.value is None:
Expand Down
1 change: 1 addition & 0 deletions mypy/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def parse_function(self, no_type_checks: bool = False) -> FuncDef:
self.errors.report(
def_tok.line, def_tok.column, 'Function has duplicate type signatures')
sig = cast(CallableType, comment_type)

if sig.is_ellipsis_args:
# When we encounter an ellipsis, fill in the arg_types with
# a bunch of AnyTypes, emulating Callable[..., T]
Expand Down
17 changes: 11 additions & 6 deletions mypy/parsetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

from mypy.sharedparse import ARG_KINDS_BY_CONSTRUCTOR, STAR_ARG_CONSTRUCTORS
Expand Down Expand Up @@ -279,6 +279,8 @@ def parse_signature(tokens: List[Token]) -> Tuple[CallableType, int]:
i = 0
if tokens[i].string != '(':
raise TypeParseError(tokens[i], i)
begin = tokens[i]
begin_idx = i
i += 1
arg_types = [] # type: List[Type]
arg_kinds = [] # type: List[int]
Expand Down Expand Up @@ -314,8 +316,11 @@ def parse_signature(tokens: List[Token]) -> Tuple[CallableType, int]:
raise TypeParseError(tokens[i], i)
i += 1
ret_type, i = parse_type(tokens, i)
return CallableType(arg_types,
arg_kinds,
[None] * len(arg_types),
ret_type, None,
is_ellipsis_args=encountered_ellipsis), i
try:
return CallableType(arg_types,
arg_kinds,
[None] * len(arg_types),
ret_type, None,
is_ellipsis_args=encountered_ellipsis), i
except (ArgKindException, ArgNameException) as e:
raise TypeParseError(begin, begin_idx, e.message)
1 change: 1 addition & 0 deletions mypy/sharedparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

STAR_ARG_CONSTRUCTORS = {'StarArg', 'KwArg'}


def special_function_elide_names(name: str) -> bool:
return name in MAGIC_METHODS_POS_ARGS_ONLY

Expand Down
13 changes: 10 additions & 3 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,20 @@ def deserialize(cls, data: JsonDict) -> 'FunctionLike':
('typ', Type),
('required', bool)])


class ArgKindException(Exception):
"""Raised when the argument kinds are not in the right order"""
message = None # type: str
def __init__(self, message: str):

def __init__(self, message: str) -> None:
self.message = message


class ArgNameException(Exception):
"""Raised when there are duplicate arg names"""
message = None # type: str
def __init__(self, message: str):

def __init__(self, message: str) -> None:
self.message = message


Expand Down Expand Up @@ -660,7 +666,8 @@ def _process_kinds_on_init(self, arg_kinds):
"after default, named or star args")
elif kind == ARG_OPT:
if self.is_var_arg or self.is_kw_arg or seen_named:
raise ArgKindException("Positional default args may not appear after named or star args")
raise ArgKindException("Positional default args may not appear "
"after named or star args")
seen_opt = True
elif kind == ARG_STAR:
if self.is_var_arg or self.is_kw_arg or seen_named:
Expand Down
11 changes: 7 additions & 4 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1412,10 +1412,13 @@ from typing import Callable
from mypy_extensions import Arg, StarArg, KwArg

def WrongArg(x, y): return y

F = Callable[[WrongArg('x', int)], int] # E: Invalid type alias
G = Callable[[Arg('x', 1)], int] # E: Invalid type alias
H = Callable[[StarArg('x', int)], int] # E: Invalid type alias # E: Too many arguments for "StarArg"
# Note that for this test, the 'Value of type "int" is not indexable' errors are silly,
# and a consequence of Callable being set to an int in the test stub. We can't set it to
# something else sensible, because other tests require the stub not have anything
# that looks like a function call.
F = Callable[[WrongArg('x', int)], int] # E: Invalid type alias # E: Value of type "int" is not indexable
G = Callable[[Arg('x', 1)], int] # E: Invalid type alias # E: Value of type "int" is not indexable
H = Callable[[StarArg('x', int)], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: Too many arguments for "StarArg"
I = Callable[[StarArg(int)], int] # ok
J = Callable[[StarArg(), KwArg()], int] # ok
K = Callable[[StarArg(), int], int] # E: Required positional args may not appear after default, named or star args
Expand Down
6 changes: 1 addition & 5 deletions test-data/unit/lib-stub/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _promote = 0
NamedTuple = 0
Type = 0
no_type_check = 0
Callable = 0

# Type aliases.
List = 0
Expand All @@ -27,11 +28,6 @@ U = TypeVar('U')
V = TypeVar('V')
S = TypeVar('S')

class _Callable(object):
def __getattr__(self, o): pass

Callable = _Callable()

class Container(Generic[T]):
@abstractmethod
# Use int because bool isn't in the default test builtins
Expand Down
11 changes: 0 additions & 11 deletions test-data/unit/parse-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,6 @@ def g(*x): # type: (X) -> Y
file:1: error: Inconsistent use of '*' in function signature
file:3: error: Inconsistent use of '*' in function signature

[case testCommentFunctionAnnotationVarArgMispatch2]
def f(*x, **y): # type: (**X, *Y) -> Z
pass
def g(*x, **y): # type: (*X, *Y) -> Z
pass
[out]
file:1: error: Inconsistent use of '*' in function signature
file:1: error: Inconsistent use of '**' in function signature
file:3: error: Inconsistent use of '*' in function signature
file:3: error: Inconsistent use of '**' in function signature

[case testPrintStatementInPython3]
Copy link
Collaborator Author

@sixolet sixolet Dec 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this test because I made **kwargs happening before *args an error no matter what, as is having more than one *args.

>>> def foo(**kwargs, *args):
  File "<stdin>", line 1
    def foo(**kwargs, *args):
                    ^
SyntaxError: invalid syntax

print 1
[out]
Expand Down
2 changes: 1 addition & 1 deletion typeshed
Submodule typeshed updated 43 files
+2 −1 .flake8
+2 −3 .travis.yml
+0 −182 CONTRIBUTING.md
+1 −10 README.md
+1 −1 requirements-tests-py3.txt
+78 −0 third_party/2/boto/__init__.pyi
+23 −34 third_party/2/boto/connection.pyi
+0 −0 third_party/2/boto/ec2/__init__.pyi
+0 −0 third_party/2/boto/ec2/elb/__init__.pyi
+27 −28 third_party/2/boto/exception.pyi
+1 −1 third_party/2/itsdangerous.pyi
+1 −1 third_party/2/werkzeug/datastructures.pyi
+2 −2 third_party/2/werkzeug/wrappers.pyi
+0 −80 third_party/2and3/boto/__init__.pyi
+0 −112 third_party/2and3/boto/auth.pyi
+0 −13 third_party/2and3/boto/auth_handler.pyi
+0 −14 third_party/2and3/boto/compat.pyi
+0 −13 third_party/2and3/boto/plugin.pyi
+0 −20 third_party/2and3/boto/regioninfo.pyi
+0 −16 third_party/2and3/boto/s3/__init__.pyi
+0 −43 third_party/2and3/boto/s3/acl.pyi
+0 −98 third_party/2and3/boto/s3/bucket.pyi
+0 −44 third_party/2and3/boto/s3/bucketlistresultset.pyi
+0 −15 third_party/2and3/boto/s3/bucketlogging.pyi
+0 −71 third_party/2and3/boto/s3/connection.pyi
+0 −23 third_party/2and3/boto/s3/cors.pyi
+0 −16 third_party/2and3/boto/s3/deletemarker.pyi
+0 −91 third_party/2and3/boto/s3/key.pyi
+0 −33 third_party/2and3/boto/s3/keyfile.pyi
+0 −55 third_party/2and3/boto/s3/lifecycle.pyi
+0 −31 third_party/2and3/boto/s3/multidelete.pyi
+0 −53 third_party/2and3/boto/s3/multipart.pyi
+0 −14 third_party/2and3/boto/s3/prefix.pyi
+0 −26 third_party/2and3/boto/s3/tagging.pyi
+0 −14 third_party/2and3/boto/s3/user.pyi
+0 −66 third_party/2and3/boto/s3/website.pyi
+0 −34 third_party/2and3/characteristic/__init__.pyi
+13 −1 third_party/2and3/mypy_extensions.pyi
+0 −1 third_party/3.6/click/core.pyi
+1 −1 third_party/3.6/click/formatting.pyi
+1 −1 third_party/3.6/click/parser.pyi
+1 −1 third_party/3.6/click/types.pyi
+1 −1 third_party/3.6/click/utils.pyi