is_annotations
函数源码
flag: TypeGuard[Annotations] = is_annotations(data: Any)
isinstance(data, Annotations)的实现。
别名
该函数可以按以下方式之一获取
import dash_picture_annotation as dpa
dpa.is_annotations
dpa.typehints.is_annotations
参数
输入
| 参数 | 类型 | 必选 | |
|---|---|---|---|
data | Any | 要验证的值。 | 
输出
| 参数 | 类型 | |
|---|---|---|
flag | bool | 若该值为True,表示data是Annotations的实例,反之亦然。 | 
范例
 检查某对象是否是Annotations
- 代码
 - 结果
 
check_is_annotations.py
import dash_picture_annotation as dpa
anno_item: dpa.AnnoItem = {
    "id": "test",
    "mark": {"x": 1, "y": 2, "width": 1, "height": 1, "type": "RECT"},
}
print(dpa.is_annotations({}))
print(dpa.is_annotations({"data": anno_item}))
print(dpa.is_annotations({"data": [anno_item]}))
print(dpa.is_annotations({"data": (anno_item,)}))
print(dpa.is_annotations([anno_item]))
print(dpa.is_annotations({"timestamp": 0, "data": [anno_item]}))
print(dpa.is_annotations({"timestamp": "0", "data": [anno_item]}))
False
False
True
False
False
True
False