Latest recipes tagged "immutable" Code RecipesFirst Class Enums in Python (Python) 2013-03-07T13:10:29-08:00James Mills <p style="color: grey"> Python recipe 578485 by <a href="/recipes/users/4167757/">James Mills</a> (<a href="/recipes/tags/enum/">enum</a>, <a href="/recipes/tags/immutable/">immutable</a>). </p> <p>True immutable symbolic enumeration with qualified value access.</p> Immutable class decorator (Python) 2012-08-05T08:30:41-07:00Oren Tirosh <p style="color: grey"> Python recipe 578233 by <a href="/recipes/users/2033964/">Oren Tirosh</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/immutable/">immutable</a>). </p> <p>Apply this decorator to a class with __slots__. Members will be mutable during the execution of __init__ but read-only afterwards.</p> A Protocol for Making Objects Immutable (Python) 2011-10-07T03:59:45-07:00Eric Snow <p style="color: grey"> Python recipe 577895 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/freeze/">freeze</a>, <a href="/recipes/tags/immutable/">immutable</a>, <a href="/recipes/tags/mutable/">mutable</a>, <a href="/recipes/tags/unfreeze/">unfreeze</a>). </p> <p>Python already provides immutable versions of many of the mutable built-in types. Dict is the notable exception. Regardless, here is a protocol that objects may implement that facilitates turning immutable object mutable and vice-versa.</p> to change instance to immutable (Python) 2011-08-08T05:52:18-07:00KATO Kanryu <p style="color: grey"> Python recipe 577831 by <a href="/recipes/users/4178894/">KATO Kanryu</a> (<a href="/recipes/tags/immutable/">immutable</a>, <a href="/recipes/tags/instance/">instance</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>make a class instance to immutable one. we can call fields, methods, and properties. This airms to make easier to develop multi thread object-oriented programming.</p> Immutable Type Hierarchies (Python) 2010-10-11T23:32:31-07:00Aaron Sterling <p style="color: grey"> Python recipe 577424 by <a href="/recipes/users/4174675/">Aaron Sterling</a> (<a href="/recipes/tags/abc/">abc</a>, <a href="/recipes/tags/hierarchy/">hierarchy</a>, <a href="/recipes/tags/immutable/">immutable</a>). Revision 4. </p> <p>Allows for type hierarchies of immutable types by faking inheritance using dict updates and abc's.</p> Immutable object(subclass) (Python) 2010-04-23T08:30:50-07:00Dmitry <p style="color: grey"> Python recipe 577207 by <a href="/recipes/users/4173772/">Dmitry</a> (<a href="/recipes/tags/immutable/">immutable</a>, <a href="/recipes/tags/object/">object</a>). Revision 2. </p> <p>Useful class and decorator for create immutable objects. Decorator mutablemethod used for define mutable methods.</p> Altering immutable string object. (Python) 2010-01-11T06:11:05-08:00Pepe Aracil <p style="color: grey"> Python recipe 577000 by <a href="/recipes/users/4171769/">Pepe Aracil</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/immutable/">immutable</a>). Revision 3. </p> <p>"Useless" alteration of immutable string object in 100% pure python. :) </p> freeze(), make any object immutable (Python) 2008-10-04T14:39:20-07:00Andreas Nilsson <p style="color: grey"> Python recipe 576527 by <a href="/recipes/users/4167183/">Andreas Nilsson</a> (<a href="/recipes/tags/const/">const</a>, <a href="/recipes/tags/freeze/">freeze</a>, <a href="/recipes/tags/immutable/">immutable</a>). Revision 2. </p> <p>Calling freeze() on an object makes the object immutable, like const in C++. Useful if you want to make sure that a function doesn't mess with the parameters you pass to it.</p> <p>Basic usage:</p> <pre class="prettyprint"><code>class Foo(object): def __init__(self): self.x = 1 def bar(f): f.x += 1 f = Foo() bar(freeze(f)) #Raises an exception </code></pre>