(self, context)
| 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 |
nothing calls this directly
no test coverage detected