Skip to content

Commit 4dda29d

Browse files
author
Naomi Seyfer
committed
Adjust tests to understand NAMED vs NAMED_OPT
1 parent 3efccb7 commit 4dda29d

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

mypy/fastparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
StarExpr, YieldFromExpr, NonlocalDecl, DictionaryComprehension,
1616
SetComprehension, ComplexExpr, EllipsisExpr, YieldExpr, Argument,
1717
AwaitExpr, TempNode, Expression, Statement,
18-
ARG_POS, ARG_OPT, ARG_STAR, ARG_NAMED, ARG_STAR2
18+
ARG_POS, ARG_OPT, ARG_STAR, ARG_NAMED, ARG_NAMED_OPT, ARG_STAR2
1919
)
2020
from mypy.types import (
2121
Type, CallableType, AnyType, UnboundType, TupleType, TypeList, EllipsisType,
@@ -363,7 +363,7 @@ def make_argument(arg: ast35.arg, default: Optional[ast35.expr], kind: int) -> A
363363

364364
# keyword-only arguments with defaults
365365
for a, d in zip(args.kwonlyargs[num_no_kw_defaults:], args.kw_defaults):
366-
new_args.append(make_argument(a, d, ARG_NAMED))
366+
new_args.append(make_argument(a, d, ARG_NAMED_OPT))
367367

368368
# **kwarg
369369
if args.kwarg is not None:

mypy/strconv.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def func_helper(self, o: 'mypy.nodes.FuncItem') -> List[object]:
4141
extra = [] # type: List[Tuple[str, List[mypy.nodes.Var]]]
4242
for i, arg in enumerate(o.arguments):
4343
kind = arg.kind # type: int
44-
if kind == mypy.nodes.ARG_POS:
44+
if kind in (mypy.nodes.ARG_POS, mypy.nodes.ARG_NAMED):
4545
args.append(o.arguments[i].variable)
46-
elif kind in (mypy.nodes.ARG_OPT, mypy.nodes.ARG_NAMED):
46+
elif kind in (mypy.nodes.ARG_OPT, mypy.nodes.ARG_NAMED_OPT):
4747
args.append(o.arguments[i].variable)
4848
init.append(o.arguments[i].initialization_statement)
4949
elif kind == mypy.nodes.ARG_STAR:
@@ -108,7 +108,8 @@ def visit_import_all(self, o: 'mypy.nodes.ImportAll') -> str:
108108
def visit_func_def(self, o: 'mypy.nodes.FuncDef') -> str:
109109
a = self.func_helper(o)
110110
a.insert(0, o.name())
111-
if mypy.nodes.ARG_NAMED in [arg.kind for arg in o.arguments]:
111+
arg_kinds = set([arg.kind for arg in o.arguments])
112+
if len(arg_kinds & set([mypy.nodes.ARG_NAMED, mypy.nodes.ARG_NAMED_OPT])) > 0:
112113
a.insert(1, 'MaxPos({})'.format(o.max_pos))
113114
if o.is_abstract:
114115
a.insert(-1, 'Abstract')

mypy/stubgen.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
from mypy.nodes import (
5656
Expression, IntExpr, UnaryExpr, StrExpr, BytesExpr, NameExpr, FloatExpr, MemberExpr, TupleExpr,
5757
ListExpr, ComparisonExpr, CallExpr, ClassDef, MypyFile, Decorator, AssignmentStmt,
58-
IfStmt, ImportAll, ImportFrom, Import, FuncDef, FuncBase, ARG_STAR, ARG_STAR2, ARG_NAMED
58+
IfStmt, ImportAll, ImportFrom, Import, FuncDef, FuncBase,
59+
ARG_STAR, ARG_STAR2, ARG_NAMED, ARG_NAMED_OPT,
5960
)
6061
from mypy.stubgenc import parse_all_signatures, find_unique_signatures, generate_stub_for_c_module
6162
from mypy.stubutil import is_c_module, write_header
@@ -261,7 +262,7 @@ def visit_func_def(self, o: FuncDef) -> None:
261262
name = var.name()
262263
init_stmt = arg_.initialization_statement
263264
if init_stmt:
264-
if kind == ARG_NAMED and '*' not in args:
265+
if kind in (ARG_NAMED, ARG_NAMED_OPT) and '*' not in args:
265266
args.append('*')
266267
typename = self.get_str_type_of_node(init_stmt.rvalue, True)
267268
arg = '{}: {} = ...'.format(name, typename)

mypy/subtypes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
# Circular import; done in the function instead.
1111
# import mypy.solve
1212
from mypy import messages, sametypes
13-
from mypy.nodes import CONTRAVARIANT, COVARIANT, ARG_POS, ARG_OPT, ARG_STAR, ARG_STAR2, ARG_NAMED, ARG_NAMED_OPT
13+
from mypy.nodes import (
14+
CONTRAVARIANT, COVARIANT, ARG_POS, ARG_OPT, ARG_STAR,
15+
ARG_STAR2, ARG_NAMED, ARG_NAMED_OPT,
16+
)
1417
from mypy.maptype import map_instance_to_supertype
1518

1619
from mypy import experiments

mypy/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
)
88

99
import mypy.nodes
10-
from mypy.nodes import INVARIANT, SymbolNode, ARG_POS, ARG_OPT, ARG_STAR, ARG_STAR2, ARG_NAMED, ARG_NAMED_OPT
10+
from mypy.nodes import (
11+
INVARIANT, SymbolNode,
12+
ARG_POS, ARG_OPT, ARG_STAR, ARG_STAR2, ARG_NAMED, ARG_NAMED_OPT,
13+
)
1114

1215
from mypy import experiments
1316

test-data/unit/parse.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ MypyFile:1(
23402340
Args(
23412341
Var(x)
23422342
Var(y))
2343-
def (x: A?, *, y: B?) -> None?
2343+
def (x: A?, *, y: B? =) -> None?
23442344
Init(
23452345
AssignmentStmt:1(
23462346
NameExpr(y)
@@ -2357,7 +2357,7 @@ MypyFile:1(
23572357
MaxPos(0)
23582358
Args(
23592359
Var(y))
2360-
def (*, y: B?) -> None?
2360+
def (*, y: B? =) -> None?
23612361
Init(
23622362
AssignmentStmt:1(
23632363
NameExpr(y)
@@ -2375,7 +2375,6 @@ MypyFile:1(
23752375
Args(
23762376
Var(y))
23772377
def (*, y: B?) -> None?
2378-
Init()
23792378
Block:1(
23802379
PassStmt:1())))
23812380

test-data/unit/semanal-types.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ MypyFile:1(
10051005
MaxPos(0)
10061006
Args(
10071007
Var(y))
1008-
def (*x: builtins.int, *, y: builtins.str) -> Any
1008+
def (*x: builtins.int, *, y: builtins.str =) -> Any
10091009
Init(
10101010
AssignmentStmt:1(
10111011
NameExpr(y [l])

0 commit comments

Comments
 (0)