def leave_Return(self, original_node: libcst.Return, updated_node: libcst.Return) -> libcst.Return: return_value = updated_node.value if not return_value: return updated_node return_whitespace = updated_node.whitespace_after_return if isinstance(return_whitespace, libcst.ParenthesizedWhitespace): return updated_node.with_changes( value=LineBreakTransformer.basic_parenthesize( return_value, return_whitespace), whitespace_after_return=libcst.SimpleWhitespace(value=" "), ) return updated_node.with_changes( value=LineBreakTransformer.basic_parenthesize(return_value))
def leave_Return( self, original_node: Return, updated_node: Return ) -> Union[BaseSmallStatement, RemovalSentinel]: if self.visiting_permalink_method and m.matches(updated_node.value, m.Tuple()): elem_0 = updated_node.value.elements[0] elem_1_3 = updated_node.value.elements[1:3] args = ( Arg(elem_0.value), Arg(Name("None")), *[Arg(el.value) for el in elem_1_3], ) return updated_node.with_changes( value=Call(func=Name("reverse"), args=args) ) return super().leave_Return(original_node, updated_node)
def remove_parentheses_from_return(self, original_node: cst.Return, updated_node: cst.Return) -> cst.Return: # We get position of the `original_node`, since `updated_node` is # by definition different and was not processed by metadata provider. position: cst.metadata.CodeRange = self.get_metadata( PositionProvider, original_node) # Removing parentheses which are used to enable multi-line expression # will lead to invalid code, so we do nothing. if position.start.line != position.end.line: return original_node return updated_node.with_deep_changes(cst.ensure_type( updated_node.value, cst.Tuple), lpar=[], rpar=[])
def remove_parentheses_from_return(self, original_node: cst.Return, updated_node: cst.Return) -> cst.Return: # We get position of the `original_node`, since `updated_node` is # by definition different and was not processed by metadata provider. position: cst.metadata.CodeRange = self.get_metadata( PositionProvider, original_node) # Removing parentheses which are used to enable multi-line expression # will lead to invalid code, so we do nothing. if position.start.line != position.end.line: return original_node # Removing parentheses around empty tuple does not make sense # and will not result in a correct Python expression (see issue #108) return_tuple = cst.ensure_type(updated_node.value, cst.Tuple) if len(return_tuple.elements) == 0: return original_node return updated_node.with_deep_changes(return_tuple, lpar=[], rpar=[])
def leave_Return(self, original_node: cst.Return, updated_node: cst.Return): updated_node = updated_node.with_changes( value=self.obf_universal(updated_node.value)) return updated_node