-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Better callable: Callable[[Arg('x', int), VarArg(str)], int] now a thing you can do
#2607
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
Changes from 1 commit
249d70f
7ecdcc1
066bd5e
213944b
0e19070
3f2f617
0b69630
f4ccf92
967bb5a
bb5134e
d4a83e1
54a5da9
e79c527
52ffe5c
06416f7
398fbad
2c9ce02
51c6f56
5e679a3
0926fe9
288a8be
6e67ab2
97a859b
1c7d4c6
f153850
be954f5
07ae917
1b97362
552f49e
f2e3663
27e2a9d
793a663
3d212b3
0780149
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -446,7 +446,7 @@ def make_argument(arg: ast3.arg, default: Optional[ast3.expr], kind: int) -> Arg | |
| new_args.append(make_argument(args.kwarg, None, ARG_STAR2)) | ||
| names.append(args.kwarg) | ||
|
|
||
| def fail_arg(msg: str, arg: ast3.arg): | ||
| def fail_arg(msg: str, arg: ast3.arg) -> None: | ||
| self.fail(msg, arg.lineno, arg.col_offset) | ||
|
|
||
| check_arg_names([name.arg for name in names], names, fail_arg) | ||
|
|
@@ -957,7 +957,7 @@ def __init__(self, errors: Errors, line: int = -1) -> None: | |
| self.line = line | ||
| self.node_stack = [] # type: List[ast3.AST] | ||
|
|
||
| def visit(self, node): | ||
| def visit(self, node) -> Type: | ||
| """Modified visit -- keep track of the stack of nodes""" | ||
| self.node_stack.append(node) | ||
| try: | ||
|
|
@@ -1021,19 +1021,16 @@ def visit_Call(self, e: ast3.Call) -> Type: | |
| value.lineno, value.col_offset) | ||
| return CallableArgument(typ, name, constructor, e.lineno, e.col_offset) | ||
|
|
||
|
|
||
| def translate_argument_list(self, l: Sequence[ast3.AST]) -> TypeList: | ||
| types = [] # type: List[Type] | ||
| names = [] # type: List[Optional[str]] | ||
| kinds = [] # type: List[int] | ||
| return TypeList([self.visit(e) for e in l], line=self.line) | ||
|
|
||
| def _extract_str(self, n: ast3.expr) -> str: | ||
|
||
| if isinstance(n, ast3.Str): | ||
| return n.s.strip() | ||
| elif isinstance(n, ast3.NameConstant) and str(n.value) == 'None': | ||
| return None | ||
| self.fail('Expected string literal for argument name, got {}'.format(type(n).__name__), self.line, 0) | ||
| self.fail('Expected string literal for argument name, got {}'.format( | ||
| type(n).__name__), self.line, 0) | ||
| return None | ||
|
|
||
| def visit_Name(self, n: ast3.Name) -> Type: | ||
|
|
@@ -1087,9 +1084,9 @@ def visit_Ellipsis(self, n: ast3.Ellipsis) -> Type: | |
|
|
||
| # List(expr* elts, expr_context ctx) | ||
| def visit_List(self, n: ast3.List) -> Type: | ||
| l = len(n.elts) | ||
| return self.translate_argument_list(n.elts) | ||
|
|
||
|
|
||
| def stringify_name(n: ast3.AST) -> Optional[str]: | ||
| if isinstance(n, ast3.Name): | ||
| return n.id | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2435,6 +2435,7 @@ def get_member_expr_fullname(expr: MemberExpr) -> str: | |
| if isinstance(obj, type) and issubclass(obj, SymbolNode) and obj is not SymbolNode | ||
| } | ||
|
|
||
|
|
||
| def check_arg_kinds(arg_kinds: List[int], nodes: List[T], fail: Callable[[str, T], None]) -> None: | ||
| is_var_arg = False | ||
| is_kw_arg = False | ||
|
|
@@ -2444,8 +2445,8 @@ def check_arg_kinds(arg_kinds: List[int], nodes: List[T], fail: Callable[[str, T | |
| if kind == ARG_POS: | ||
| if is_var_arg or is_kw_arg or seen_named or seen_opt: | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change messaging to refer to "var args" |
||
| fail("Required positional args may not appear " | ||
| "after default, named or star args", | ||
| node) | ||
| "after default, named or star args", | ||
| node) | ||
| break | ||
| elif kind == ARG_OPT: | ||
| if is_var_arg or is_kw_arg or seen_named: | ||
|
|
@@ -2467,7 +2468,7 @@ def check_arg_kinds(arg_kinds: List[int], nodes: List[T], fail: Callable[[str, T | |
|
|
||
|
|
||
| def check_arg_names(names: List[str], nodes: List[T], fail: Callable[[str, T], None], | ||
| description: str = 'function definition') -> None: | ||
| description: str = 'function definition') -> None: | ||
| seen_names = set() # type: Set[str] | ||
| for name, node in zip(names, nodes): | ||
| if name is not None and name in seen_names: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,7 @@ def deserialize(cls, data: JsonDict) -> 'UnboundType': | |
| return UnboundType(data['name'], | ||
| [deserialize_type(a) for a in data['args']]) | ||
|
|
||
|
|
||
| class CallableArgument(Type): | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring here. |
||
| typ = None # type: Type | ||
| name = None # type: Optional[str] | ||
|
|
@@ -254,6 +255,7 @@ def deserialize(cls, data: JsonDict) -> 'CallableArgument': | |
| name=data['name'], | ||
| constructor=data['constructor']) | ||
|
|
||
|
|
||
| class TypeList(Type): | ||
| """Information about argument types and names [...]. | ||
|
|
||
|
|
@@ -1431,9 +1433,9 @@ def visit_type_list(self, t: TypeList) -> str: | |
| def visit_callable_argument(self, t: CallableArgument) -> str: | ||
| typ = t.typ.accept(self) | ||
| if t.name is None: | ||
| return "{}({})".format(t.constructor, t.typ) | ||
| return "{}({})".format(t.constructor, typ) | ||
| else: | ||
| return "{}({}, {})".format(t.constructor, t.typ, t.name) | ||
| return "{}({}, {})".format(t.constructor, typ, t.name) | ||
|
|
||
| def visit_any(self, t: AnyType) -> str: | ||
| return 'Any' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment about why it makes sense to just return
typhere and elsewhere in this file.