pymel.util.metaStatic

digraph inheritance345f49a8a2 {
rankdir=TB;
ranksep=0.15;
nodesep=0.15;
size="8.0, 12.0";
  "metaStatic" [fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,URL="../pymel.util.utilitytypes/pymel.util.utilitytypes.metaStatic.html#pymel.util.utilitytypes.metaStatic",style="setlinewidth(0.5)",height=0.25,shape=box,fontsize=8];
  "Singleton" -> "metaStatic" [arrowsize=0.5,style="setlinewidth(0.5)"];
  "Singleton" [fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,URL="../pymel.util.utilitytypes/pymel.util.utilitytypes.Singleton.html#pymel.util.utilitytypes.Singleton",style="setlinewidth(0.5)",height=0.25,shape=box,fontsize=8];
}

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