Table of Contents

Class: Attribute ./src/peak/binding/once.py

Descriptor for Component Attribute Bindings

Attribute is a Descriptor with additional features to make component interconnection easier. Specifically, Attribute adds the ability to automatically adapt computed or assigned values to a specific interface, and the ability to automatically "suggest" to an assigned value that the containing object should become its parent component. In addition, Attribute has various metadata attributes that can be read by a containing class, to enable various features such as "offering" the attribute as a supplier of a particular interface or configuration key.

In addition, if an Attribute is placed in a binding.Component subclass (or any class whose metaclass derives from binding.Activator), it will automatically discover its attrName from the class, so that you don't have to explicitly supply it.

Attribute is primarily an abstract base class; you will ordinarily use Make, Obtain, Require, or Delegate instead. However, all of those subclasses accept the same keyword arguments, and have the same basic lazy initialization and caching behavior. They differ only in how they compute the attribute value, and in their constructors' positional arguments.

In addition to the attributes defined by the Descriptor base class, Attribute instances also have the following attributes, which may be overridden in subclasses, or by supplying constructor keyword arguments:

offerAs
A sequence of configuration keys under which the attribute should be registered. This tells the containing Component class to offer the attribute's value to child components when they look up any of the specified configuration keys. Values in the supplied sequence will be adapted to the config.IConfigKey interface. Default value: an empty list. (Note that this attribute has no effect unless the Attribute is placed in a binding.Component subclass.)
uponAssembly
A flag indicating whether the attribute should be initialized as soon as its containing component is part of a complete component hierarchy. Default value: False. (Note that this attribute has no effect unless the Attribute is placed in a binding.Component subclass.)
doc
A docstring, used to give an appropriate representation of the attribute when it's rendered by pydoc or the Python help() function.
adaptTo
the interface that values of this attribute should be adapted to, or None. If not None, then whenever the attribute is set (or its computeValue() result is cached), the value will be adapted to this interface before being stored. If adaptation fails, a NotImplementedError will be raised. (Note that this behavior is implemented by 'Attribute.onSet()'; if you override the default onSet(), this adaptation will not take place unless your replacement does it.)
suggestParent
should assigned values be informed that they are being attached to the containing component? This value defaults to True, so you should set it to False if you do not want the attachment to happen. If True, then whenever the attribute is set (or its computeValue() result is cached), suggestParentComponent() will be called to let the value know that the containing component may be the value's parent component, and what attribute name it is being referenced by. Note that this call happens after the value is first adapted to the adaptTo interface, if applicable, and is also performed by Attribute.onSet(), so the same warning about overriding onSet() applies here.

Base Classes   
Descriptor
    BaseDescriptor
Methods   
__delete__
__get__
__repr__
__set__
_copyWithName
_installedDescr
activateInClass
onSet
  __delete__ 
__delete__ (
        self,
        ob,
        value,
        )

  __get__ 
__get__ (
        self,
        ob,
        typ=None,
        )

  __repr__ 
__repr__ ( self )

  __set__ 
__set__ (
        self,
        ob,
        value,
        )

  _copyWithName 
_copyWithName ( self,  attrName )

  _installedDescr 
_installedDescr ( self,  klass )

Return a newly installed descriptor proxy to use, or raise a usage error if self doesn't know its own right name.

  activateInClass 
activateInClass (
        self,
        klass,
        attrName,
        )

  onSet 
onSet (
        self,
        obj,
        attrName,
        value,
        )


Table of Contents

This document was automatically generated on Mon Apr 7 01:11:03 2025 by HappyDoc version 2.1