Skip to main content

Python decorators library

Project description

Python More Decorators

Python More Decorators is a handy library to simplify your code with a collection of useful decorators.

  • Works with type checking (tested with mypy)

Installation

pip

pip install python-more-decorators

poetry

poetry add python-more-decorators

Features

Evaluate runtime-default arguments

Sometimes we are just tired of polluting the function arguments declaration with None as argument: Optional[MutableType] = None. Or, we have all been here: having some_list_argument: list[T] = [] or now: float = time.time() in arguments.

The worst thing is that it still runs.

We now have:

from more_decorators.runtime_defaults import evaluate_runtime_defaults, runtime_default

@evaluate_runtime_defaults
def foo(now: float = runtime_default(time.time)): # think of it like `now: float = time.time()`
                                                  # but evaluated every time upon function call
    return f"Unix Timestamp: {now}"

...and more to come.

License

This library is licensed under the MIT License. See the LICENSE file for details.

Development

See CONTRIBUTING.md

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

more_decorators-0.1.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

more_decorators-0.1.1-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

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