A sophisticated type system enhancement library for metaprogramming and runtime behavior modification
Project description
metacore
⚠️ EARLY ALPHA WARNING: This library is in early development and the API may change significantly between versions. Use at your own risk in production environments.
A sophisticated type system enhancement library for Python metaprogramming and runtime behavior modification.
Overview
metacore bridges the gap between static type hints and runtime behavior by making types first-class citizens in the runtime environment. It provides powerful tools for:
- Immutable constant namespaces with automatic type coercion
- Extensible type annotation processing via registry pattern
- Enhanced exception handling with formatted tracebacks
- Runtime type validation and conversion
Features
ConstantNamespace
Create immutable constant namespaces with automatic type coercion at class definition time:
from metacore.meta.classes.constants import ConstantNamespace
import pathlib
class MyConstants(ConstantNamespace):
# Regular attributes (not annotated) are not constants
A = 1
# Annotated attributes become immutable constants
B: int = 2
C: int = 3.4 # Coerced to 3
# Advanced type coercion
path: pathlib.Path = "documents/test.txt" # Coerced to Path object
numbers: list[int] = [1, 1.5, 3] # Coerced to [1, 1, 3]
# Access constants
print(MyConstants.B) # 2
print(MyConstants.path) # PosixPath('documents/test.txt')
# Modification is prevented
MyConstants.C = 10 # Raises ConstantsModificationError
# Dict-like interface
MyConstants.items() # [('B', 2), ('C', 3), ...]
MyConstants.keys() # ('B', 'C', 'path', 'numbers')
MyConstants.get('B', default=0) # 2
Type Annotation Processing
Extensible registry-based type processing system:
from metacore.meta.typing_utilities.annotations_processors.processors import (
annotation_registry,
ValidationLevel
)
registry = annotation_registry()
# Convert values to match type annotations
result = registry.convert_to_annotation(list[int], ("42", 4.2)) # Returns [42, 4]
# Register custom type handlers
@registry.register_processor(MyCustomType)
def process_custom_type(value, annotation):
# Custom conversion logic
return MyCustomType(value)
Enhanced Exceptions
All library exceptions inherit from TracedException for better debugging:
from metacore.abstract.exceptions.traced_exceptions import TracedException
class MyError(TracedException):
"""Custom exception with formatted traceback"""
pass
Installation
pip install metacore
Requirements
- Python 3.12 or higher
Development Status
This library is in active alpha development. The current focus is on refactoring the annotation processing system into a modular architecture. Breaking changes may occur between minor versions.
Roadmap
tbd
Contributing
This is an early-stage project. Contributions, bug reports, and feedback are welcome but please be aware of the alpha status.
License
MIT License - see LICENSE file for details.
Author
Sébastien Gachoud
Note: Some code and tests were developed with assistance from Claude AI.
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 sg_metacore-0.1.0a0.tar.gz.
File metadata
- Download URL: sg_metacore-0.1.0a0.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a81d10749dd6c179a52142d26b305ba5dcb29b0d29254c4931fc7af445dd2f6
|
|
| MD5 |
b2aea29e0d4ef7ffc9f6160ecb26ab29
|
|
| BLAKE2b-256 |
5c9b5905388718b20bc6b5d9f73458a2e09ec4029e2d9a00eb7b6bf4ae8377b8
|
File details
Details for the file sg_metacore-0.1.0a0-py3-none-any.whl.
File metadata
- Download URL: sg_metacore-0.1.0a0-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8886257f66ffeb64720c196ad3c8501cbc41726380d8545181f64bd2a192e18
|
|
| MD5 |
a73e238f4b589e5f8f1a13d1f5621229
|
|
| BLAKE2b-256 |
f2efa0cf449b20bba7d978ffcff270a12e85dbe0a888d5aed963f6d15f775a05
|