bokeh.core.has_props#

提供一个基类,用于具有声明性、类型化、可序列化属性的对象。

注意

这些类构成了实现Bokeh模型和属性系统的非常底层的机制的一部分。这些类或其方法不太可能适用于任何标准用途,也不适用于那些不直接在Bokeh自身基础设施上进行开发的人员。

class HasProps(**properties: Any)[source]#

所有具有Bokeh属性的类类型的基类。

__init__(**properties: Any) None[source]#
apply_theme(property_values: dict[str, Any]) None[source]#

应用一组主题值,这些值将用于替代默认值,但不会覆盖应用程序设置的值。

传入的字典可能会保持原样并与其他实例共享以节省内存(因此调用者和HasProps实例都不应修改它)。

Parameters:

property_values (dict) – 用于替换默认值的主题值

Returns:

clone(**overrides: Any) Self[源代码]#

复制一个HasProps对象。

这将创建原始模型的浅克隆,即任何可变的容器或子模型将不会被复制。允许在克隆时覆盖特定属性。

classmethod dataspecs() dict[str, DataSpec][source]#

收集此类上所有DataSpec属性的名称。

此方法始终遍历类层次结构,并包括在任何父类上定义的属性。

Returns:

DataSpec 属性的名称

Return type:

set[str]

classmethod descriptors() list[PropertyDescriptor[Any]][源代码]#

属性描述符的列表,按定义的顺序排列。

equals(other: HasProps) bool[源代码]#

模型的结构相等性。

Parameters:

其他 (HasProps) – 要比较的其他实例

Returns:

如果属性在结构上相等,则为True,否则为False

classmethod lookup(name: str, *, raises: Literal[True] = True) PropertyDescriptor[Any][源代码]#
classmethod lookup(name: str, *, raises: Literal[False] = False) PropertyDescriptor[Any] | None

在类上找到Bokeh属性的PropertyDescriptor,给定属性名称。

Parameters:
  • name (str) – 要搜索的属性的名称

  • raises (bool) – 如果缺失,是抛出异常还是返回None

Returns:

名为name的属性的描述符

Return type:

PropertyDescriptor

classmethod properties(*, _with_props: Literal[False] = False) set[str][source]#
classmethod properties(*, _with_props: Literal[True] = True) dict[str, Property[Any]]

收集此类的属性名称。

警告

在Bokeh的未来版本中,此方法将返回一个将属性名称映射到属性对象的字典。为了使当前使用此方法的方式具有未来兼容性,请将返回值包装在list中。

Returns:

属性名称

classmethod properties_with_refs() dict[str, Property[Any]][源代码]#

收集此类上所有具有引用的属性的名称。

此方法始终遍历类层次结构,并包括在任何父类上定义的属性。

Returns:

具有引用的属性名称

Return type:

set[str]

properties_with_values(*, include_defaults: bool = True, include_undefined: bool = False) dict[str, Any][源代码]#

收集一个将属性名称映射到其值的字典。

此方法始终遍历类层次结构,并包括在任何父类上定义的属性。

不可序列化的属性将被跳过,属性值以“序列化”格式呈现,这可能与您通常从属性中读取的值略有不同;此方法的目的是返回无损重构对象实例所需的信息。

Parameters:

include_defaults (bool, optional) – 是否包含自对象创建以来未明确设置的属性。(默认值:True)

Returns:

从属性名称到其值的映射

Return type:

dict

query_properties_with_values(query: Callable[[PropertyDescriptor[Any]], bool], *, include_defaults: bool = True, include_undefined: bool = False) dict[str, Any][源代码]#

使用谓词查询HasProps实例的属性值。

Parameters:
  • query (callable) – 一个可调用对象,接受属性描述符并返回 True 或 False

  • include_defaults (bool, optional) – 是否包含用户未明确设置的属性(默认值:True)

Returns:

属性名称和值的映射,用于匹配属性

Return type:

dict

set_from_json(name: str, value: Any, *, setter: Setter | None = None) None[source]#

从JSON设置此对象的属性值。

Parameters:
  • name (str) – 要设置的属性名称

  • value (JSON-value) – 要设置给属性的值

  • setter (ClientSessionServerSessionNone, 可选) –

    这用于防止对Bokeh应用程序的“回旋镖”更新。

    在Bokeh服务器应用程序的上下文中,对属性的传入更新将使用正在执行更新的会话进行注释。该值通过更新触发的任何后续更改通知传播。会话可以将事件设置器与自身进行比较,并抑制源自自身的任何更新。

Returns:

themed_values() dict[str, Any] | None[source]#

获取任何主题提供的覆盖。

结果以属性名称到值的字典形式返回,如果此实例没有主题覆盖任何值,则返回None

Returns:

字典或无

to_serializable(serializer: Serializer) ObjectRep[source]#

将此对象转换为可序列化的表示形式。

unapply_theme() None[源代码]#

移除任何主题值并恢复默认设置。

Returns:

update(**kwargs: Any) None[source]#

从给定的关键字参数更新对象的属性。

Returns:

示例

以下是等价的:

from bokeh.models import Range1d

r = Range1d

# set properties individually:
r.start = 10
r.end = 20

# update properties together:
r.update(start=10, end=20)
class MetaHasProps(class_name: str, bases: tuple[type, ...], class_dict: dict[str, Any])[source]#

专门化HasProps类的构建。

这个类是一个元类,用于HasProps,负责创建和添加PropertyDescriptor实例,这些实例将验证和序列化委托给Property属性。

property model_class_reverse_map: dict[str, type[HasProps]]#
class NonQualified[source]#

通过非限定名称解析此类。

class Qualified[source]#

通过完全限定名称解析此类。

abstract(cls: C) C[source]#

一个用于标记从HasProps派生的抽象基类的装饰器。