Skip to content

Commit

Permalink
Error for bare asterisk after *args
Browse files Browse the repository at this point in the history
Fixes python#13
  • Loading branch information
etrepum committed Jul 25, 2014
1 parent 3c2e712 commit 1252799
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mypy/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,22 @@ def parse_arg_list(
assigns = [] # type: List[Token]

require_named = False
bare_asterisk_before = -1

if self.current_str() != ')' and self.current_str() != ':':
while self.current_str() != ')':
if self.current_str() == '*' and self.peek().string == ',':
if require_named:
# can only have one bare star, must be before any
# *args or **args
self.parse_error()
self.expect('*')
require_named = True
bare_asterisk_before = len(args)
elif self.current_str() in ['*', '**']:
if bare_asterisk_before == len(args):
# named arguments must follow bare *
self.parse_error()
asterisk.append(self.skip())
isdict = asterisk[-1].string == '**'
name = self.expect_type(Name)
Expand Down Expand Up @@ -540,11 +549,13 @@ def parse_arg_list(
else:
kinds.append(nodes.ARG_OPT)
else:
if require_named:
self.parse_error()
init.append(None)
assigns.append(none)
kinds.append(nodes.ARG_POS)
if require_named:
# required keyword-only argument
kinds.append(nodes.ARG_NAMED)
else:
kinds.append(nodes.ARG_POS)

if self.current().string != ',':
break
Expand Down

0 comments on commit 1252799

Please sign in to comment.