Table of Contents

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

Class whose instances are itself, with all attributes at class level

Subclass binding.Singleton to create true (per-interpreter) singleton objects. Any attribute bindings defined will apply to the class itself, rather than to its instances. Any attempt to create an instance of a singleton class will simply return the class itself. The self of all methods will also be the class.

This actually works by redefining all the singleton class' attributes as binding.classAttr() objects, causing them to be placed in a new metaclass created specifically for the singleton class. So, if you would otherwise find yourself using classmethod or binding.classAttr() on all the contents of a class, just subclass binding.Singleton instead.

Note that if you define special methods like __new__() or __init__(), these will also be promoted to the metaclass. This means, for example, that if you define an __init__ method, it will be called with the singleton class object (or a subclass) when the class is created.

Base Classes   
object
Methods   
__new__
  __new__ 
__new__ ( klass )


Table of Contents

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