Skip to main content

Unstable

Because sometime documenting a function is unstable is not enough.

Because often, reaching to the documentation to know if something is stable takes too much time.

Because once it’s stable, you’ll forget to re-check again.

Installation

$ pip install unstable

Utility

This module provides a decorator to mark function as unstable. Unstable function will raise an UnstableWarningunless used in an unstable context. Thus preventing you from using an unstable function by mistake.

Provide an with unstable() context manger which silence (or log) the exceptions raised by unstable functions. By default an unstable context manager that does not detect any use of unstable functions will log a StableWarning.

See Readme for more information.

Usage

Mark a function as unstable

from unstable import unstable

@unstable
def frobulate(frumious, bandersnatch):
    galumphing(frumious) + bandersnatch

Mark a branch as being unstable

from unstable import unstable

def galumphing(frumious):
    if frumious:
        unstable.here_be_dragons(reason='frumious=True')
        # ...
    else:
        # ...

Using unstable code

By default unstable code will raise an UnstableWarning, wrap unstable code in an unstable context manager.

from unstable import unstable

with unstable:
    fumious(True, 25) # Will Behave

frumious(False, 18) # will Fail with UnstableWarning

galumphing(False) # fine

with unstable:
    galumphing(True) # fine

Context manager or decorator ?

Q : Is unstable a context manager or decorator ? A : Both. It’s magic.

Advance usage:

I need to write the doc, PR welcome.

Why ?

Inspired by Rust’s #[Unstable], which allows you to use it only explicitly (and I’m not talking about safety here). This mimick it (as much as it can).

I want to be able to “ship” unstable code and N.x version of a library and tell users “Use at your own risk”, though no-one read the doc. Here it make things obvious, don’t use it unless you meant to. Also the “instability” in contagious as function using unstable functions will become (partially) unstable. The instability boundary is obvious, it’s the context manager.

What about try/except ?

It will/can catch the exception, though the called function will not run.

Todo

Add a plugin for sphinx which automatically mark the function in the doc as unstable.

Release files for unstable 0.5.1

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

Built distribution (wheel)

Table of built distributions (wheels) for unstable 0.5.1
File Interpreter ABI Platform
unstable-0.5.1-py3-none-any.whl Python 3 none any Details

Release files / unstable-0.5.1-py3-none-any.whl

Download URL unstable-0.5.1-py3-none-any.whl
Size 74.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
331c29b1bcb9521cb4319957d1493563b1d0a8f289e53a6fe6bd45e3d3bf261e
BLAKE2b-256 checksum
How to use checksums
802b08592d9bf22f536bea640b7828e5f7b817190c9e22f0b8305ffb82cf48df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5.1 This release

1 release file

0.5.0

1 release 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