Skip to main content

Decorator for your functions, for easy tune of boolean arguments

Project description

# Magwitch
The magical switch switcher !

import magwitch

def save_figure(in_png:bool=False, legend:bool=True):
... # an implementation we do not care about for the example
return in_png

# Now, you can set the value of the boolean arguments by giving their name:
assert save_figure.in_png() is True

# Or not:
assert save_figure.not_in_png() is False

# Also, you can do it multiple times:

# The last set is autoritative
assert f.not_in_png.in_png() is True

# And there is many other options if you want to !
@magwitch.on_with(use_defaults=True, enable='do_', disable=('nope_', 'never_'):
def f(a:bool=False): return a

# effect of use_defaults
assert f.do_a() is False

See the [tests](test/) for complete API, and the docstring of ``
for a description of all available parameters.

Install with

pip install magwitch

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

magwitch-0.1.0.tar.gz (3.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page