Heads up, link broken ttps://docs.python.org/3/glossary.html#term-immutabl (looks like copy past missed beginning and end)!
In Listing 7. Presumably “def _init_(self, field):” should be “def _init_(self, field = None):”. Default value added.
Captions to figures don’t make sense, e.g. “Figure 5: Before freezing Die – immutable objects drawn in “ice blue” with dashed borders and references from immutable objects drawn with lighter blue lines.” There are no “dashed borders” nor “lighter blue lines”.
What is the intension with data classes, they aren’t mentioned in the PEP?
Have you considered using a with statement to make both the programmer’s and type-checker’s life easier:
class Die:
def __init__(self, sides=6):
self.set_sides(sides)
def set_sides(self, sides):
self.sides = sides
def roll(self):
# Importing a mutable module is OK
import random
return random.randint(1, self.sides)
d = Die(6)
with Immutable(d):
# Immutable stuff
The with statement above would be shorthand for:
freeze(Die)
freeze(d)
# Immutable stuff
unfreeze(d)
unfreeze(Die)
@hlovatt, could you please use a different forum than this one (which has many subscribers) to do what looks like an edit pass – e.g. typos can be handled just as well via a private message? And if you must, please collect your feedback into a single, coherent comment.