Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def p_varargslist20(self, p):
''' varargslist : fpdef EQUAL test varargslist_list COMMA '''
# def f(a=1, b=2,): pass
list_args, list_defaults = p[4]
if len(list_args) != len(list_defaults):
msg = 'non-default argument follows default argument.'
tok = FakeToken(p.lexer.lexer, p.lineno(2))
syntax_error(msg, tok)
args = [p[1]] + list_args
defaults = [p[3]] + list_defaults
p[0] = self._make_args(args, defaults=defaults)
def _validate_template_inst(self, node, lexer):
""" Validate a template instantiation.
This function ensures that the bindings on the instantiation refer
to declared identifiers on the instantiation.
"""
names = set()
if node.identifiers:
names.update(node.identifiers.names)
for binding in node.body:
if binding.name not in names:
msg = "'%s' is not a valid template id reference"
syntax_error(msg % binding.name,
FakeToken(lexer, binding.lineno))
def check_const(name, node):
msg = None
if name in param_names:
msg = "declaration of 'const %s' shadows a parameter"
elif name in const_names:
msg = "redeclaration of 'const %s'"
if msg is not None:
syntax_error(msg % name, FakeToken(lexer, node.lineno))
const_names.add(name)
"""
kwnames = set()
args = []
kws = []
self._validate_arglist_list(items, p.lexer.lexer)
for arg in items:
if isinstance(arg, ast.keyword):
kws.append(arg)
kwnames.add(arg.arg)
else:
args.append(arg)
for kw in keywords:
if not isinstance(kw, ast.keyword):
msg = 'only named arguments may follow *expression'
tok = FakeToken(p.lexer.lexer, p.lineno(2))
syntax_error(msg, tok)
if kw.arg in kwnames:
msg = 'keyword argument repeated'
tok = FakeToken(p.lexer.lexer, kw.lineno)
syntax_error(msg, tok)
kwnames.add(kw.arg)
kws.extend(keywords)
return args, kws
def p_error(self, t):
msg = 'invalid syntax'
lexer = t.lexer
# Ply has a weird thing where sometimes we get the EnamlLexer and
# other times we get the Ply lexer
if isinstance(lexer, self.lexer):
lexer = lexer.lexer
syntax_error(msg, FakeToken(lexer, t.lineno))
def _validate_storage_expr(self, kind, lineno, lexer):
if kind not in ('attr', 'event'):
syntax_error('invalid syntax', FakeToken(lexer, lineno))
def p_varargslist17(self, p):
''' varargslist : fpdef EQUAL test varargslist_list COMMA STAR fpdef COMMA DOUBLESTAR fpdef '''
# def f(a=1, b=2, *args, **kwargs)
list_args, list_defaults = p[4]
if len(list_args) != len(list_defaults):
msg = 'non-default argument follows default argument.'
tok = FakeToken(p.lexer.lexer, p.lineno(2))
syntax_error(msg, tok)
args = [p[1]] + list_args
defaults = [p[3]] + list_defaults
p[0] = self._make_args(args, defaults=defaults, vararg=p[7],
kwarg=p[10])