make an object read only
Robin Becker
robin at reportlab.com
Tue Aug 2 11:12:47 EDT 2016
A reportlab user found he was doing the wrong thing by calling canvas.save
repeatedly, our documentation says you should not use Canvas objects after the
save method has been used. The user had mixed results :(
It would be better to make the canvas object completely immutable all the way
down when save has been called, but I think that's quite hard as these objects
have quite a large and varied set of attributes, lists other objects
dictionaries etc etc.
I can think of some strategies for making the object unusable eg changing it's
class and getting rid of __dict__, but that disallows referencing valid
properties eg pagesize, fontName, etc etc.
Is there a way to recursively turn everything immutable?
--
Robin Becker
More information about the Python-list
mailing list