Skip to main content

A lightweight Python metaclass for enforcing required attributes and types in class hierarchies

Project description

Pact: Attribute Enforcement Metaclass for Python

Pact is a lightweight Python metaclass designed to enforce the presence and types of class attributes in subclasses
It helps you ensure that all subclasses implement the required attributes declared in the base class,
catching missing or mistyped attributes early with warnings and exceptions

Features

  • Enforce presence of specific class or instance attributes in subclasses
  • Type validation of annotated attributes
  • Raises PactException exception and emits warnings for missing or mismatched attributes

Installation

You can install this package via PIP: pip install python-pact

Usage

from pact import Pact


class Person(Pact):
    name: str
    age: int


class JohnDoe(Person):
    name = 'John Doe'
    age = 25


# This will raise PactException due to missing 'age':
class JaneDoe(Person):
    name = 'Jane Doe'

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

python_pact-0.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

python_pact-0.1.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_pact-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for python_pact-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e9886bb41d86fcc2b6956ce733e8510f427b96775fd2f3b708261fc80b31ed41
MD5 750791780788ce5987c9d19d1e2115c8
BLAKE2b-256 70f8bc048b66f2e208823670bf92745ff6691f45fb84153a8fb0e28c01dabe52

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_pact-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for python_pact-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c030870d12597836c133b74a845e76ed013c84f610df2e7cea36dea5b17cd45
MD5 64fb09f520a72af966e305e5a6a6d784
BLAKE2b-256 18dc4df95a354cda8cdf66100d4f791828f7d6f4d16681226f57952692e277be

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