Table of Contents

Class: classAttr ./src/peak/binding/attributes.py

Class attribute binding

This wrapper lets you create bindings which apply to a class, rather than to its instances. This can be useful for creating bindings in a base class that will summarize metadata about subclasses. Usage example:

        class SomeClass(binding.Component):

            CLASS_NAME = binding.classAttr(
                binding.Make(
                    lambda self: self.__name__.upper()
                )
            )

        class aSubclass(SomeClass):
            pass

        assert SomeClass.CLASS_NAME == "SOMECLASS"
        assert aSubclass.CLASS_NAME == "ASUBCLASS"

Class attributes will only work in subclasses of classes like binding.Component, whose metaclass derives from binding.Activator.

Implementation note: class attributes actually cause a new metaclass to be created on-the-fly to contain them. The generated metaclass is named for the class that contained the class attributes, and has the same __module__ attribute value. So continuing the above example:

        assert SomeClass.__class__.__name__ == 'SomeClassClass'
        assert aSubClass.__class__.__name__ == 'SomeClassClass'

Notice that the generated metaclass is reused for subsequent subclasses, as long as they don't define any new class attributes.

Base Classes   
object
Methods   
__init__
  __init__ 
__init__ ( self,  binding )


Table of Contents

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