Skip to main content

contextlib-ext - extensions for contextlib

Build Status

contextlib-ext is a complimentary library for contextlib, it provides a following helpers:

suppress as a decorator

suppress can be used as a decorator

from contextlib_ext import suppress

@suppress(Exception)
def phony_func():
    raise ValueError

phony_func()
print("No exceptions")

@asynccontextmanager creates decorator

@asynccontextmanager creates context manager that can be used as a decorator (contextlib.contextmanager already supports it)

from contextlib_ext import asynccontextmanager

@asynccontextmanager
async def mymanager():
    yield

# The same as contextlib.asynccontextmanager
async with mymanager():
    pass

# This also works
@mymanager
async def myfunc():
    pass

async_suppress

async_suppress - the same as suppress, but async

from contextlib_ext import async_suppress

try:
  async with async_suppress(Exception):
      raise ValueError
except Exception:
  assert False  # never happens
else:
  print("No exceptions")

# Works as decorator too

@async_suppress(Exception)
async def phony_func():
    raise ValueError

phony_func()
print("No exceptions")

Download files

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

Source Distribution

contextlib-ext-0.0.0.tar.gz (2.3 kB view details)

Uploaded Source

File details

Details for the file contextlib-ext-0.0.0.tar.gz.

File metadata

  • Download URL: contextlib-ext-0.0.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for contextlib-ext-0.0.0.tar.gz
Algorithm Hash digest
SHA256 115ab1a9ae858725bd586f917496acec764761533219338a426f8f3bc27ba66b
MD5 cfdd835969acc5846d0aa9ab1c1aecf2
BLAKE2b-256 5ef5ce0f732fd534e89740e7d70078a97618f6be039f959e1bf53bf175591969

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.0 This release

1 file

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