跳转到主要内容

对象可观测性库

项目描述

bigbrother

一个邪恶、糟糕、可怕、糟糕的库,用于监视对象的更改。请不要使用此库。

Build Status Coverage License PyPI

概述

bigbrother 是一个变更观察器库。您可以使用它来监视您的对象的更改。当您的对象发生变化时,bigbrother 将触发您选择的回调。

x = {1: "a", 2: "b", 3: "c"}

def track_changes(obj, method, ref, call_args, call_kwargs):
    print(f"method: {method}, args: {args}, kwargs: {kwargs}")

x = watch(x, track_changes)

x[1] = "x"

# prints: method: setitem, args: (1, 'x'), kwargs: {}

bigbrother 还可以通过传递参数 deepstate=True 递归地嵌入到您的对象中。

回调

def callback(obj, method, ref, call_args, call_kwargs):
    '''Callback called when object is mutated

    Args:
        obj (Any): The object being mutated via `method`
        method (str): The method called on the object (dunders removed)
        ref (Any): Reference object. If callback installed recursively, `ref` will be the entrypoint
        call_args (Tuple[Any]): Positional arguments that `method` was called with on `obj`
        call_kwargs (Dict[Any, Any]): Keyword arguments that `method` was called with on `obj`
    '''

支持类型

内置类型

大多数内置类型是只读的,无法更改其方法结构,因此我们通过替换薄包装器进行观察。

  • list 通过 _ObservedList
    • append
    • clear
    • extend
    • insert
    • pop
    • remove
    • sort
    • __setattr__
    • __setitem__
  • dict 通过 _ObservedDict
    • clear
    • pop
    • popitem
    • update
    • __setattr__
    • __setitem__
  • set 通过 _ObservedSet
    • add
    • clear
    • difference_update
    • discard
    • intersection_update
    • pop
    • remove
    • symmetric_difference_update
    • update
    • __setattr__

  • pydantic.BaseModel

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

bigbrother-0.1.3.tar.gz (19.8 kB 查看哈希值)

上传时间

构建分发

bigbrother-0.1.3-py3-none-any.whl (19.1 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面