Skip to main content

Uplevel

Access the values of variables in the parent scope. This package provides two commands: upvar and upset.

Installation

pip install uplevel

Usage

Here is a short example of how to use upvar command:

from uplevel import upvar

def fib(stop: int, step: int = 0):
    if step < 2:
        result = 0 if step == 0 else 1
    elif step <= stop:
        previous = upvar(1, 'result')  # result from previous iteration
        preprevious = upvar(2, 'result')  # and one iteration before
        result = previous + preprevious
    else:
        return upvar(1, 'result')
    return fib(stop, step + 1)

print(fib(20))

Here is another example for the upset command. It provides the feature to inject a variable into a parent scope. This can be useful but it also might upset people who read this code.

import re
from uplevel import upset


def simplematch(regex, string):
    results = re.match(regex, string)
    upset(1, 'match', results)
    return results


if simplematch(r"[abc]+", "abc123"):
    print(f"Matched: {match.group(0)}")

Metadata

Release files for uplevel 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uplevel 0.0.5
File Size Uploaded
uplevel-0.0.5.tar.gz 2.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uplevel 0.0.5
File Interpreter ABI Platform
uplevel-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 4.3 kB

Release files / uplevel-0.0.5.tar.gz

Download URL uplevel-0.0.5.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d4bb91572e25f127b0a84368c0a07dcee9a157dcfb405f160de4f9f59812118b
BLAKE2b-256 checksum
How to use checksums
36c0e05386ea73218e0132fd609f4a05d1ee6af27035d0168a21b37995d2de6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / uplevel-0.0.5-py3-none-any.whl

Download URL uplevel-0.0.5-py3-none-any.whl
Size 2.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa1d4146219c624b4e1c106101eae1b2845b641ebc623b0e6541656f11e8b558
BLAKE2b-256 checksum
How to use checksums
5e7c0f5e32dfe626dcb058b469a665897890556a58dc84f382a3a2ac25b44de2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page