Skip to main content

Context manager that will skip the body on a condition.

All code is in conditional_context/__init__.py

Examples

Condition function example

from conditional_context import condition

print('start')
value = True
with condition(False):
    value = False
    print('here')  # Will not print
print('end')

assert value

Custom class replacing the should_skip method example

import conditional_context

class MyContext(conditional_context.ConditionalContext):
    def should_skip(self):
        return True

print('start')
value = True
with MyContext():
    value = False
    print('here')  # Will not print
print('end')

assert value

Replace the should_skip method with a decorator

import conditional_context

ctx = conditional_context.ConditionalContext()

@ctx.replace_should_skip
def my_should_skip():
    return True

print('start')
value = True
with ctx:
    value = False
    print('here')  # Will not print
print('end')

assert value, 'ConditionalContext class did not skip properly'

Breakout function to stop running the context without showing an error.

from conditional_context import condition

value1 = True
value2 = True
value3 = True
with condition() as ctx:
    value1 = False
    value2 = False
    ctx.breakout()  # Should raise an error to break out of the context.
    value3 = False

assert value1 is False
assert value2 is False
assert value3 is True, 'The breakout feature did not work as expected!'

Metadata

Release files for conditional-context 1.1.0

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

Source distribution (sdist)

Source distribution for conditional-context 1.1.0
File Size Uploaded
conditional_context-1.1.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for conditional-context 1.1.0
File Interpreter ABI Platform
conditional_context-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / conditional_context-1.1.0.tar.gz

Download URL conditional_context-1.1.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a1444f08877a96c0acacbe3f37a735e6103b54584f636e8ac8a497133e2a0ecd
BLAKE2b-256 checksum
How to use checksums
2647028490dd7124c8026a975691d5d464fc4d502115214b315d010d7aecfaca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

Release files / conditional_context-1.1.0-py3-none-any.whl

Download URL conditional_context-1.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d733345b41d1e163983183bff544e8f277a26ff6e28ddb062d1c9e15b11036d8
BLAKE2b-256 checksum
How to use checksums
03cbc38811d306cbf320c4057f871f51067d4f1e93a4b773c05b8e761d956899
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

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