Skip to main content

strict-abc

CI PyPI version Python versions License: MIT Ruff mypy

strict-abc provides StrictABCMeta and StrictABC, which validate concrete implementations of abstract methods at class definition time.

The goal is to fail fast when a subclass violates LSP-friendly signature rules.

Installation

pip install strict-abc-lsp

Usage

from abc import abstractmethod

from strict_abc import StrictABC


class BaseService(StrictABC):
    @abstractmethod
    def process(self, data: dict, cache: bool = True) -> str:
        ...


class ValidService(BaseService):
    def process(self, data: dict, cache: bool = True) -> str:
        return "ok"

This works.

But this raises TypeError at class definition time:

class InvalidService(BaseService):
    def process(self, data: dict, cache: bool) -> str:
        return "ok"

Because removing a default value strengthens the precondition.

Options

Configure validation with __strict_options__:

class Base(StrictABC):
    __strict_options__ = {
        "check_names": True,
        "check_defaults": True,
        "check_types": True,
        "check_return_type": True,
    }

    @abstractmethod
    def fetch(self, url: str) -> bytes:
        ...

Default options:

{
    "check_names": False,
    "check_defaults": True,
    "check_types": False,
    "check_return_type": False,
}

Development

Install dependencies:

make install

Run lint, type check, tests, build and dist check:

make all

Install pre-commit hooks:

make pre-commit-install

Run tests with coverage:

make cov

Publishing

For TestPyPI:

poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi <YOUR_TESTPYPI_TOKEN>
make publish-test

For PyPI:

poetry config pypi-token.pypi <YOUR_PYPI_TOKEN>
make publish

License

MIT

Metadata

Release files for strict-abc-lsp 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 strict-abc-lsp 0.1.0
File Size Uploaded
strict_abc_lsp-0.1.0.tar.gz 6.9 kB Details

Built distribution (wheel)

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

Total release size: 14.6 kB

Release files / strict_abc_lsp-0.1.0.tar.gz

Download URL strict_abc_lsp-0.1.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5b7218def7d21378687314291d98bfa3afd28263821e8aac7f088323af6dc999
BLAKE2b-256 checksum
How to use checksums
bef93fc82c5862b7f5d04137ac50503899a2b23c6a213406f0786bbb7f4778e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.2 Darwin/25.5.0

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

Download URL strict_abc_lsp-0.1.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b68f5e87ea4cc474b78b6d70071fc41c563e874ca34429ed8b556a52fc7065b
BLAKE2b-256 checksum
How to use checksums
b797eb62e580e6a141092d1ba0dfbd10b621442a5658501d395178417e59c311
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.2 Darwin/25.5.0

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

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