Mutable Object Declaration - 支持声明与实现分离的类定义库
Project description
mutobj
mutobj (Mutable Object Declaration) - 支持声明与实现分离的 Python 类定义库。
特性
- 声明与实现分离 - 类似 C/C++ 头文件模式
- Extension 机制 - 为类添加私有状态而不污染接口
- IDE 友好 - 完整支持 mypy/pyright 和 IDE 跳转
- 继承支持 - 完整的类继承和方法覆盖
- 零依赖 - 纯 Python 实现,无外部依赖
安装
pip install mutobj
快速开始
声明文件 (user.py)
import mutobj
class User(mutobj.Declaration):
name: str
age: int
def greet(self) -> str:
"""返回问候语"""
...
实现文件 (user_impl.py)
import mutobj
from .user import User
@mutobj.impl(User.greet)
def greet(self: User) -> str:
return f"Hello, I'm {self.name}!"
使用
from user import User
import user_impl # 导入以注册实现
user = User(name="Alice", age=25)
print(user.greet()) # "Hello, I'm Alice!"
Extension 机制
为类添加私有状态:
class UserExt(mutobj.Extension[User]):
_login_count: int = 0
def __extension_init__(self):
self._login_count = 0
@mutobj.impl(User.greet)
def greet(self: User) -> str:
ext = UserExt.of(self)
ext._login_count += 1
return f"Hello, {self.name}! (login #{ext._login_count})"
支持的功能
| 功能 | 状态 |
|---|---|
| 属性声明 | ✅ |
| 方法声明与实现 | ✅ |
| Property | ✅ |
| classmethod | ✅ |
| staticmethod | ✅ |
| 继承 | ✅ |
| Extension | ✅ |
| 类型检查 | ✅ |
文档
开发
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
pytest
# 类型检查
mypy src/mutobj
发布
Tag 触发自动发布(PyPI Trusted Publishers,无需 token):
git tag v0.2.x
git push origin v0.2.x
源码版本保持 x.y.999,CI 从 tag 提取正式版本号替换后构建发布。
License
MIT License - 详见 LICENSE
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
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 mutobj-0.7.1.tar.gz.
File metadata
- Download URL: mutobj-0.7.1.tar.gz
- Upload date:
- Size: 37.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8b3ee9a5108ce929daee761f3a780051483fb6e50373dcdfcd24b1a96241d70
|
|
| MD5 |
be370779ebc00c80a74659d235d6e3db
|
|
| BLAKE2b-256 |
ed2171d33fcd41014433dcf809804cb1f5a69e23f134cab160349197b5db173f
|
Provenance
The following attestation bundles were made for mutobj-0.7.1.tar.gz:
Publisher:
release.yml on tiwb/mutobj
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mutobj-0.7.1.tar.gz -
Subject digest:
c8b3ee9a5108ce929daee761f3a780051483fb6e50373dcdfcd24b1a96241d70 - Sigstore transparency entry: 1368311663
- Sigstore integration time:
-
Permalink:
tiwb/mutobj@2d9f4b40ad99215446ce5a967ccb76107accee72 -
Branch / Tag:
refs/tags/v0.7.1 - Owner: https://github.com/tiwb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2d9f4b40ad99215446ce5a967ccb76107accee72 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mutobj-0.7.1-py3-none-any.whl.
File metadata
- Download URL: mutobj-0.7.1-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6f6fead27e0902ce9fc5a6ffbe21cc071b0f7419d002d53f4acdbc4c71b30f4
|
|
| MD5 |
f71ec1a3aa97721b91ba6a61d91c66a7
|
|
| BLAKE2b-256 |
4b88bd82c3ca628cdab902ec00f5fc6c7fe1586d4875a35ed2de7d7ff6256b7f
|
Provenance
The following attestation bundles were made for mutobj-0.7.1-py3-none-any.whl:
Publisher:
release.yml on tiwb/mutobj
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mutobj-0.7.1-py3-none-any.whl -
Subject digest:
a6f6fead27e0902ce9fc5a6ffbe21cc071b0f7419d002d53f4acdbc4c71b30f4 - Sigstore transparency entry: 1368311669
- Sigstore integration time:
-
Permalink:
tiwb/mutobj@2d9f4b40ad99215446ce5a967ccb76107accee72 -
Branch / Tag:
refs/tags/v0.7.1 - Owner: https://github.com/tiwb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2d9f4b40ad99215446ce5a967ccb76107accee72 -
Trigger Event:
push
-
Statement type: