Skip to content
This repository has been archived by the owner on Dec 31, 2021. It is now read-only.

Latest commit

 

History

History
53 lines (45 loc) · 842 Bytes

README.md

File metadata and controls

53 lines (45 loc) · 842 Bytes

Rusty Return

Return the last statement of function if it is a expression. Depends on ast.NodeTransformer and inspect.getsource.

Example

@rlr
def add(x, y):
    x + y
    
assert add(2, 3) == 5
@rlr
def gt(x, y):
    if x > y:
        True
    elif x == y:
        4
    elif x + 1 == y:
        if x > y:
            True
        else:
            if True:
                33
            else:
                False
    else:
        False

assert gt(10, 2) is True
assert gt(2, 10) is False
assert gt(2, 2) == 4
assert gt(2, 3) == 33
@rlr
class Calculator:
    def add(self, x, y):
        x + y
    
    def sub(self, x, y):
        x - y
    
    def mul(self, x, y):
        result = 0
        for _ in range(y):
            result += x
        
        result

assert Calculator().add(2, 3) == 5