[Python-Dev] PEP 318 (was re: redefining is)
Josiah Carlson
jcarlson at uci.edu
Thu Mar 25 10:33:22 EST 2004
> > > Heh, another use for the class variant of PEP 318. Josiah's code
> > > depends on knowing which classes have immutable instances, using a
> > > hardcoded set of builtin types. With PEP318, one could do
> > >
> > > class foo [immutable]:
> > > ...
> > >
> > > with an appropriate definition of immutable that either decorates the
> > > class object or adds to the set of known immutables. Perhaps also with
> > > code to catch and warn against obvious attempts at mutation of foos...
>
> This PEP is losing its innocence.
>
> Having been repeatedly confronted with FUD arguments in other contexts,
> I hate to put on that hat, but I do not think it wise to support too
> many varieties of weirdness. Heck, we've already got meta-classes for
> that.
I think David was just pointing out that if one had a class decorator
that /just happened/ to do what the name suggested, it would also happen
to work nicely with the earlier code posted as to whether an object is
replaceable by a different object.
> > One could even include the disclaimer that any code that modifies an
> > instance that is supposed to be immutable, is inherantly broken and is
> > not supported
>
> <fud>
> I'm sensing an unnamed code smell.
> </fud>
I've not really seen any code that makes an attempt to be read-only, but
has some hooks to allow it to be written, so I don't know if your
properly named FUD is warranted or not. Documentation-wise, it would be
something that makes sense to insert 'anything that modifies an
immutable through holes in the interface, is broken', if in the future
Python decides to have some sort of immutability decorator or 'provides
immutability' syntax.
I wasn't implying anything huge, just a relatively minor it should be
documented in the future when/if it becomes available.
- Josiah
More information about the Python-Dev
mailing list