MCPcopy Create free account
hub / github.com/SourceCode-AI/aura / unary_op

Method unary_op

aura/analyzers/python/rewrite_ast.py:332–361  ·  view source on GitHub ↗
(self, context)

Source from the content-addressed store, hash-verified

330 context.replace(new_node)
331
332 def unary_op(self, context):
333 if not type(context.node) in (dict, OrderedDict):
334 return
335 elif context.node.get("_type") != "UnaryOp":
336 return
337
338 operand = context.node["operand"]
339
340 if type(operand) == Number:
341 value = operand.value
342 elif type(operand) in (int, float):
343 value = operand
344 else:
345 # Incompatible operand type
346 return
347
348 op_name = context.node["op"]["_type"]
349 if op_name == "UAdd":
350 op = lambda x: +x
351 elif op_name == "USub":
352 op = lambda x: -x
353 elif op_name == "Invert":
354 op = lambda x: ~x
355 else:
356 return
357
358 new_node = Number(value=op(value))
359 new_node.enrich_from_previous(context.node)
360 context.replace(new_node)
361 return True
362
363 def return_statement(self, context):
364 if not isinstance(context.node, ReturnStmt): # Covers also yield and yield from

Callers

nothing calls this directly

Calls 3

NumberClass · 0.85
getMethod · 0.80
enrich_from_previousMethod · 0.80

Tested by

no test coverage detected