Skip to main content

abstractsignature

This package provides a method for enforcing consistent function signatures between abstractmethod implementations. This hopes to make large libraries where many classes inherit a common interface from a single abstract definition easier to maintain.

Classes which inherit an @abstractmethod with an @abstractsignature will fail to instantiate if their signature does not equal the abstraction.

Two signatures are considered equal if all their parameters are equal (excluding the implicit self/cls parameter for instance and class methods), their positional and positional only parameters are in the same order, and they have equal return annotations. Parameters are considered equal if they have the same name, kind, default value, and annotation.

Install

Install from git:

uv add git+https://github.com/d-c-gray/abstractsignature.git

Usage

Create a class that inherits from ABCSignature, and define abstract methods. Add the @abstractsignature decorator above the @abstractmethod decorator.

from abstractsignature import abstractsignature, ABCSignature
from abc import abstractmethod

class MyInterface(ABCSignature):
    @abstractsignature
    @abstractmethod
    def my_method(self, a: int) -> int:
        return a + 1

class MyImplementation(MyInterface):
    def __init__(self):
        super().__init__()
    def my_method(self, number: int) -> int:
        return number + 1

MyImplementation()

If the implemented signature doesn't match the defined signature, you will get an error:

abstractsignature.abstractsignature.IncorrectSignatureError: implementation <bound method MyImplementation.my_method of <__main__.MyImplementation object at 0x00000135A7E1EE40>> does not match abstract definition of <class '__main__.MyInterface'>:
Implemented signature:
 (number: int) -> int
Abstract signature:
 (a: int) -> int

This pattern also works with @classmethod and @staticmethod

from abstractsignature import abstractsignature, ABCSignature
from abc import abstractmethod

class MyInterface(ABCSignature):
    @classmethod
    @abstractsignature
    @abstractmethod
    def my_class_method(cls, a: int) -> int:
        return a + 1

    @staticmethod
    @abstractsignature
    @abstractmethod
    def my_static_method(cls, a: int) -> int:
        return a + 1

This project was built from simple-modern-uv.

Metadata

Release files for abstractsignature 0.1.0

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

Source distribution (sdist)

Source distribution for abstractsignature 0.1.0
File Size Uploaded Provenance
abstractsignature-0.1.0.tar.gz 31.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 36.5 kB

Release files / abstractsignature-0.1.0.tar.gz

Download URL abstractsignature-0.1.0.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
07631b6d4651e9bd637fc6d0e0e59a21a68859edbbfd6b7aa034d07efb8af0ad
BLAKE2b-256 checksum
How to use checksums
bd876d5130fcc4bd05a100836ace7d0b5db6146ed793d72221a60d01e48cfb9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.5

Release files / abstractsignature-0.1.0-py3-none-any.whl

Download URL abstractsignature-0.1.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a12e280b8483e92cc569ffefee19db0aacaaa08bc96e72569a62f5ebd42d8ab2
BLAKE2b-256 checksum
How to use checksums
7f20df22947b4eb20c6c7f26986ec7e0a8c64a26b6e151f49031fb0dce26175f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.5

Security for abstractsignature 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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