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

isidentical-archive/rustyreturn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

RLR (rust-like-return) for python functions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages