Skip to main content

mutobj

Python 3.11+ License: MIT

mutobj (Mutable Object Declaration) - 支持声明与实现分离的 Python 类定义库。

特性

  • 声明与实现分离 - 类似 C/C++ 头文件模式
  • Extension 机制 - 为类添加私有状态而不污染接口
  • IDE 友好 - 完整支持 mypy/pyright 和 IDE 跳转
  • 继承支持 - 完整的类继承和方法覆盖
  • 零依赖 - 纯 Python 实现,无外部依赖

安装

pip install mutobj

快速开始

import mutobj

class User(mutobj.Declaration):
    name: str
    age: int

    def greet(self) -> str: ...

@mutobj.impl(User.greet)
def user_greet(self: User) -> str:
    return f"Hello, I'm {self.name}!"

user = User(name="Alice", age=25)
print(user.greet())  # "Hello, I'm Alice!"

字段声明、方法覆盖、继承、Extension 私有状态、Implementation 类等详见 使用指南

Lint 工具

在 pytest 中执行运行时 lint,检查 @impl 命名规范、签名一致性等:

from mutobj.lint import check

def test_lint() -> None:
    results = check(["mypkg.*"])
    if results:
        pytest.fail(results.format())

详见 使用指南 §5.4

开发

# 安装开发依赖
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

Release files for mutobj 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mutobj 0.9.1
File Size Uploaded
mutobj-0.9.1.tar.gz 81.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mutobj 0.9.1
File Interpreter ABI Platform
mutobj-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 128.5 kB

Release files / mutobj-0.9.1.tar.gz

Download URL mutobj-0.9.1.tar.gz
Size 81.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d9689f9c063f5b099872b5a1eba8d191b8ab5c0a5d8b25ad34975037b613f739
BLAKE2b-256 checksum
How to use checksums
439ce2189d88169f530fb98021a3a8e24f90f7c64ca58e59d9363516f1d571f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / mutobj-0.9.1-py3-none-any.whl

Download URL mutobj-0.9.1-py3-none-any.whl
Size 46.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
486e6c85ea9d0488f8f25d5515a287198d7c2a74dd3d3a136a26bb6d1e623c57
BLAKE2b-256 checksum
How to use checksums
9904ac6e86a8209f626279649776eb8e34a9123708128a5148c97aab374cff90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.2.2

2 release files

0.2.1

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