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
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 abcreg-0.1.2.tar.gz.
File metadata
- Download URL: abcreg-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c601e7809401ba21817c6ce038fecee505afd2535da8e482e2ed2d491468152d
|
|
| MD5 |
7ccf51a72a0466825f9a1c441730b487
|
|
| BLAKE2b-256 |
2774a5e6d286c4126d549d1c847a6e959183b345f978b507bc7e03e980bf7f89
|
File details
Details for the file abcreg-0.1.2-py3-none-any.whl.
File metadata
- Download URL: abcreg-0.1.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a25c51a38bbe20b5e2bf4e11fce63032b76d58a55f169ab1d248d2a85b84735
|
|
| MD5 |
d3f53735a1eb36d45cc2b899db8ddb56
|
|
| BLAKE2b-256 |
50901142e8f42806715e970ce6f004d104b34b7dd7a7c7172127016aae2a7a12
|