[Python-Dev] PEP 318 (was re: redefining is)

Bob Ippolito bob at redivi.com
Wed Mar 24 21:02:12 EST 2004


On Mar 24, 2004, at 6:37 PM, Josiah Carlson wrote:

>>> You were there and helped point out some of the limitations of the
>>> original code I posted, which now has a _straightforward_ recursive
>>> implementation here:
>>> http://mail.python.org/pipermail/python-dev/2004-March/043357.html
>>
>> 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...
>
> 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.  Of course the testing before and after method calls and
> attribute access would be difficult, if not impossible with current
> Python.

it could also be simply:

class foo [provides(Immutability)]:
     pass

or...

declareImplements(int, instancesImplement=(Immutability,))

Basically what you want, when you are declaring type information, is a 
way to find the type information.  You don't really know nor care if 
it's actually part of the type object.  It's actually better that it's 
not, such as when you are declaring stuff about types that you can't 
change -- like int, long, etc.  It just so happens that PyProtocols (or 
something like it, but I demonstrate PyProtocols syntax) already takes 
care of this for you.

-bob




More information about the Python-Dev mailing list