pymel.util.metaStatic

Inheritance diagram of metaStatic

class metaStatic

A static (immutable) Singleton metaclass to quickly build classes holding predefined immutable dicts

>>> class FrozenDictSingleton(dict) :
...    __metaclass__ = metaStatic
...
>>> FrozenDictSingleton({'A':1})
{'A': 1}
>>> a = FrozenDictSingleton()
>>> a
{'A': 1}
>>> b = FrozenDictSingleton()
>>> a, b
({'A': 1}, {'A': 1})
>>> a is b
True
>>> b = FrozenDictSingleton({'B':2})
Traceback (most recent call last):
    ...
TypeError: 'FrozenDictSingleton' object does not support redefinition
>>> a['A']
1
>>> a['A'] = 2   
Traceback (most recent call last):
    ...
TypeError: '<class '...FrozenDictSingleton'>' object does not support item assignation
>>> a.clear()
Traceback (most recent call last):
    ...
AttributeError: 'FrozenDictSingleton' object has no attribute 'clear'
>>> a, b, FrozenDictSingleton()
({'A': 1}, {'A': 1}, {'A': 1})
>>> a is b and a is FrozenDictSingleton()
True
>>> class StaticTest(FrozenDictSingleton):
...     pass
...
>>> StaticTest({'A': 1})
{'A': 1}
>>> a = StaticTest()
>>> a
{'A': 1}
>>> b = StaticTest()
>>> a, b
({'A': 1}, {'A': 1})
>>> class StaticTest2( StaticTest ):
...     pass
...
>>> StaticTest2({'B': 2})
{'B': 2}
>>> a = StaticTest2()
>>> a
{'B': 2}
>>> b = StaticTest2()
>>> a, b
({'B': 2}, {'B': 2})

Previous topic

pymel.util.metaReadOnlyAttr

Next topic

pymel.util.path

Core

Core Modules

Other Modules

This Page