A library to help with the management of alternative implementations of functions
Project description
This is a library to help with the management of alternative implementations of functions, as you may have when optimising.
import alternative
@alternative.reference
def constant_number():
return 1
@constant_number.add(default=True)
def alternative_constant_number():
return 2
@constant_number.add
def unused_alternative_constant_number():
return 3
# the reference implementation is substituted with the default implementation - if no default was specified, the reference would have been used
assert constant_number() == 2
# alternative implementations still act like themselves
assert unused_alternative_constant_number() == 3
# TODO: mash in measure + benchmark + equality tests from examples
The library tries to avoid unpleasant surprises that may come from import orders or maintenance issues:
- the implementation that is used cannot be changed once it has been used
- implementations cannot be added once they have been inspected: reduces the changes of tests only covering a subset of
Running with ALTERNATIVE_DEBUG=1 as an environment variable will result in the library recording which lines were
responsible for critical state changes like the point that a default implementation was selected or the implementations
were inspected. These are then used in error messages which can be used to resolve stateful issues.
For how this can tie in with equivalence checks and benchmarking in pytest, see the examples directory.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alternative-0.1.0.tar.gz.
File metadata
- Download URL: alternative-0.1.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64459f682ef1518e871674c912eaba0986c778a4c6127a10905cdb685728df07
|
|
| MD5 |
acd70f5cb6cf17de1b768abfc15384a0
|
|
| BLAKE2b-256 |
8a9091dd69eba91f46248e7833e06ca5c798e4224ab78c43026c385d581afbb8
|
Provenance
The following attestation bundles were made for alternative-0.1.0.tar.gz:
Publisher:
publish.yml on Code0x58/alternative
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alternative-0.1.0.tar.gz -
Subject digest:
64459f682ef1518e871674c912eaba0986c778a4c6127a10905cdb685728df07 - Sigstore transparency entry: 702525721
- Sigstore integration time:
-
Permalink:
Code0x58/alternative@6594c5da22f77bdefd36659c07a6c0fccf503863 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/Code0x58
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6594c5da22f77bdefd36659c07a6c0fccf503863 -
Trigger Event:
release
-
Statement type:
File details
Details for the file alternative-0.1.0-py3-none-any.whl.
File metadata
- Download URL: alternative-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
149d5c2fdd8fe3c76b489d8c17aecfc203cd3ebbc279e957568f348f368d2174
|
|
| MD5 |
68e9af60717605bbb941d65752ee9a78
|
|
| BLAKE2b-256 |
8f857d075714d08331e2ba5aea1173952a99db575c7560cd2e775a344fba64b8
|
Provenance
The following attestation bundles were made for alternative-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Code0x58/alternative
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alternative-0.1.0-py3-none-any.whl -
Subject digest:
149d5c2fdd8fe3c76b489d8c17aecfc203cd3ebbc279e957568f348f368d2174 - Sigstore transparency entry: 702525762
- Sigstore integration time:
-
Permalink:
Code0x58/alternative@6594c5da22f77bdefd36659c07a6c0fccf503863 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/Code0x58
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6594c5da22f77bdefd36659c07a6c0fccf503863 -
Trigger Event:
release
-
Statement type: