def get_target(self, target):
if isinstance(target, ast.Subscript) and self.context.in_for_loop: # Check if we are doing assignment of an iteration loop.
raise_exception = False
if isinstance(target.value, ast.Attribute):
list_name = "%s.%s" % (target.value.value.id, target.value.attr)
if list_name in self.context.in_for_loop:
raise_exception = True
if isinstance(target.value, ast.Name) and \
target.value.id in self.context.in_for_loop:
list_name = target.value.id
raise_exception = True
if raise_exception:
raise StructureException("Altering list '%s' which is being iterated!" % list_name, self.stmt)
if isinstance(target, ast.Name) and target.id in self.context.forvars:
raise StructureException("Altering iterator '%s' which is in use!" % target.id, self.stmt)
target = Expr.parse_variable_location(target, self.context)
if target.location == 'storage' and self.context.is_constant:
raise ConstancyViolationException("Cannot modify storage inside a constant function: %s" % target.annotation)
if not target.mutable:
raise ConstancyViolationException("Cannot modify function argument: %s" % target.annotation)
return target
评论列表
文章目录