Skip to main content

Checked inheritance for Abstract Base Classes

Project description

ABCReg

ABCReg adds AnnotatedABC and AnnotatedABCMeta, which provide additional interface checking at registration time to ensure that registered virtual and ordinary subclasses are valid.

Use ABCReg if you are designing a plugin API or any other interface that might be implemented by an end user.

Defining the Interface

Use AnnotatedABC just like an ordinary ABC. Make sure to mark your API methods as abstract and provide type hints:

from abc import abstractmethod
from abcreg import AnnotatedABC

class Queryable(AnnotatedABC):
    @abstractmethod
    def query(self, **kwargs) -> str: ...

We recommend you use virtual inheritance:

@Queryable.register
class VirtualQueryProvider:
    def query(self, **kwargs) -> str:
        return "query result"

assert issubclass(VirtualQueryProvider, Queryable)
assert isinstance(VirtualQueryProvider(), Queryable)

But, regular inheritance will also work:

class QueryProvider(Queryable):
    def query(self, **kwargs) -> str:
        return "query result"

assert issubclass(QueryProvider, Queryable)

Requirements and Usage

Requries Python 3.10+. With UV, require with uv add abcreg.

Development

Pre-build checks: `` uv sync --all-groups uv run ruff check --fix uv run ruff format --preview uv run mypy abcreg

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

abcreg-0.1.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

abcreg-0.1.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file abcreg-0.1.1.tar.gz.

File metadata

  • Download URL: abcreg-0.1.1.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for abcreg-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a0396d5806226b30209cd57f0ac0b771d1984ad102cf56e452eacf3acd2f018e
MD5 2ed7c9f819f316ead070241b07a2fa3b
BLAKE2b-256 b379bfa387746d0c1359943f1d4c631b2bcd113ae3d695334aaedcdc196fc59e

See more details on using hashes here.

File details

Details for the file abcreg-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: abcreg-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for abcreg-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 67e3a48945a36bacf075639b33c693a83169618aa028c5f3b2ad40e5982fc489
MD5 fa1e7d90ff3f7a27c2f3d9b03408ad59
BLAKE2b-256 1f40f2a67aeb35f720ad7c5832637393aaa5e8778e92cb583d40ea78b88c2f53

See more details on using hashes here.

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