Skip to main content

Return last statement of functions.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for RustyReturn, version 0.2.3
Filename, size File type Python version Upload date Hashes
Filename, size RustyReturn-0.2.3.tar.gz (1.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page