bokeh.core.property.descriptor_factory¶
すべてのBokeh属性に1つの基底クラスを提供する.
Bokeh属性の働き方は、Python記述子オブジェクトを貢献することです HasProps
授业。そして,これらの記述子は属性アクセスをBokeh Propertyクラスに戻し,後者は検証,直列化,文書要求を処理する.
♪the PropertyDescriptorFactory
クラスは2つの方法を提供する autocreate
そして make_descriptors
元類で使われています MetaHasProps
クラス作成中に宣言された属性に対応する必要な記述子を作成してインストールします。
このメカニズムはBokehをより人間的にするのに役立つ。たとえば,DataSpec属性は固定値と列データソース列への参照の間で調停される.ユーザは非常に簡単な文法を使用することができ、属性は自動的に正しく直列化され、検証される:
from bokeh.models import Circle
c = Circle()
c.x = 10 # serializes to {'value': 10}
c.x = 'foo' # serializes to {'field': 'foo'}
c.x = [1,2,3] # raises a ValueError validation exception
Bokeh全体には他にも似たような例が多い。このようにして、ユーザは、検証、直列化、および文書に関する下位の詳細に関心を持たずに、簡単かつ自然に操作することができる。
注釈
これらのクラスは,Bokehモデルと属性システムを実現する非常に下位の機器の一部を構成している.これらのクラスまたはそれらの方法のいずれも、任意の標準的な用法に適用される可能性はあまりなく、またはBokeh自身のインフラ上で直接開発された誰でもない。
-
class
PropertyDescriptorFactory
[ソース]¶ すべてのBokeh属性の基底クラス.
A Bokeh property really consist of two parts: the familiar "property" portion, such as
Int
,String
, etc., as well as an associated Python descriptor that delegates attribute access (e.g.range.start
) to the property instance.以下のクラス定義を考慮してください。
from bokeh.model import Model from bokeh.core.properties import Int class SomeModel(Model): foo = Int(default=10)
次のような点が観察されます
>>> m = SomeModel() # The class itself has had a descriptor for 'foo' installed >>> getattr(SomeModel, 'foo') <bokeh.core.property.descriptors.BasicPropertyDescriptor at 0x1065ffb38> # which is used when 'foo' is accessed on instances >>> m.foo 10