Skip to content

TelegramXPlus/can-raise

Repository files navigation

can-raise

A simple library for decorating functions that can raise exceptions.

Installation

pip install can-raise

Usage

from can_raise import can_raise

@can_raise(ValueError)
def validate_int(x: int):
    if x < 0:
        raise ValueError
    return x

If you don't provide any value, it will default to Exception

@can_raise()
def raise_exc():
    raise TypeError # or any other exception

You can also provide more than one argument

@can_raise(ValueError, TypeError)
def raise_exc(x: int):
    if x < 0:
        raise ValueError
    if x > 0:
        raise TypeError
    return x

About

A simple library for decorating functions that can raise exceptions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages