Skip to main content

A library to help with the management of alternative implementations of functions

Project description

PyPi Package Build Status Coverage Report

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alternative-0.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alternative-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for alternative-0.1.0.tar.gz
Algorithm Hash digest
SHA256 64459f682ef1518e871674c912eaba0986c778a4c6127a10905cdb685728df07
MD5 acd70f5cb6cf17de1b768abfc15384a0
BLAKE2b-256 8a9091dd69eba91f46248e7833e06ca5c798e4224ab78c43026c385d581afbb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for alternative-0.1.0.tar.gz:

Publisher: publish.yml on Code0x58/alternative

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for alternative-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 149d5c2fdd8fe3c76b489d8c17aecfc203cd3ebbc279e957568f348f368d2174
MD5 68e9af60717605bbb941d65752ee9a78
BLAKE2b-256 8f857d075714d08331e2ba5aea1173952a99db575c7560cd2e775a344fba64b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for alternative-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Code0x58/alternative

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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