Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _validate_decl_funcdef(self, funcdef, lexer):
walker = ast.walk(funcdef)
next(walker) # discard toplevel funcdef
for item in walker:
if type(item) in self._DECL_FUNCDEF_DISALLOWED:
msg = '%s not allowed in a declarative function block'
msg = msg % self._DECL_FUNCDEF_DISALLOWED[type(item)]
syntax_error(msg, FakeToken(lexer, item.lineno))
def _validate_storage_expr(self, kind, lineno, lexer):
if kind not in ('attr', 'event'):
syntax_error('invalid syntax', FakeToken(lexer, lineno))
def p_expr_stmt3(self, p):
''' expr_stmt : testlist_star_expr equal_list '''
all_items = [p[1]] + p[2]
targets = list(map(ast_for_testlist, all_items))
value = targets.pop()
for item in targets:
if type(item) == ast.Yield:
msg = "assignment to yield expression not possible"
syntax_error(msg, FakeToken(p.lexer.lexer, item.lineno))
self.set_context(item, Store, p)
assg = ast.Assign()
assg.targets = targets
assg.value = value
p[0] = assg
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)
def check_id(name, node):
if name in ident_names:
msg = "redeclaration of identifier '%s'"
msg += " (this will be an error in Enaml version 1.0)"
syntax_warning(msg % name, FakeToken(lexer, node.lineno))
ident_names.add(name)
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 p_arglist13(self, p):
''' arglist : STAR test COMMA arglist_list argument '''
kwnames = set()
keywords = p[4] + [p[5]]
for kw in keywords:
if not isinstance(kw, ast.keyword):
msg = 'only named arguments may follow *expression'
tok = FakeToken(p.lexer.lexer, p.lineno(1))
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)
p[0] = Arguments(keywords=keywords, starargs=p[2])
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_varargslist_list3(self, p):
''' varargslist_list : varargslist_list COMMA fpdef '''
list_args, list_defaults = p[1]
if list_defaults:
msg = 'non-default argument follows default argument.'
tok = FakeToken(p.lexer.lexer, p.lineno(2))
syntax_error(msg, tok)
args = list_args + [p[3]]
p[0] = (args, list_defaults)