Skip to main content

Divert the execution flow.

Project description

Divert

Divert the execution flow of your code. This is useful for complex code with lots of method nesting and unpredictable return values.

Plus, no sub-dependencies.

Example usage

For example, if we have an inner function (or multiple), we can immediately divert to a flow edge of our choice.

from divert.flow import custom_flow_edge, divert


def inner_function(number: int) -> int:
    """Function that doubles the value or signals that the flow should change."""
    if number == 4:  # Stop condition for sake of example
        divert()  # If we want to specify the return value here we can instead use `payload_to_edge(VALUE)`

    return number * 2


@custom_flow_edge(default_return=42)
def outer_function() -> int:
    """Larger function that calls the inner function multiple times."""
    first_response = inner_function(2)
    second_response = inner_function(4)
    third_response = inner_function(8)

    return first_response + second_response + third_response

For further motivation for using the library, see the documentation. For example usage, see the examples.

Project details


Download files

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

Source Distribution

divert-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

divert-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file divert-0.1.0.tar.gz.

File metadata

  • Download URL: divert-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for divert-0.1.0.tar.gz
Algorithm Hash digest
SHA256 be5cef0d59febd05d7f6409da38edecc5ab9261aa75577579b2e9e40a35b4567
MD5 4f581245ec83d737ca1863bf312ae513
BLAKE2b-256 aa7c51a236167f32d2af20a061c220ee608abc7b6288b65ed626a9f4c96a3aa0

See more details on using hashes here.

File details

Details for the file divert-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: divert-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for divert-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3ce5af62af8f55b584bf97414529c8cbc7d8e5bed4c537dd36f7c5558cb085d
MD5 09c5b7e9fd72572583580d63b150616f
BLAKE2b-256 720f14a46e25348c70242adafdbf04ca63faa94b97185ab2bc140caca921fcaa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page