any interest in type-scoped static constants?

Paul Prescod paulp at ActiveState.com
Sun Mar 11 14:29:42 EST 2001


Paul Miller wrote:
> 
> ...
> 
> If I create an extension type for Point, I can't do this:
> 
>         p = Point.ZERO
> 
> But I'd like to.

Yes you can! 

[out of order]
> .... 
> My solution would be to add a dictionary to the extension type for
> constants, that the extension code can initialize, and then add a
> scoping test for Type.ATTR to add a check in the Type's attribute
> dictionary.

Right, you can do this in any extension type.

> I'm seriously considering working on a patch to add type-specific
> constants to provide OO access to extension type constants, rather than
> putting all constants in the module scope. I wonder if anyone has
> started this, and if this is considered a good idea. Do I need to write
> a PEP?

Why do you need a PEP when you can implement it for any extension you
need. Just put a dictionary in the type and using type.getattr to look
stuff up in your dictionary.

-- 
Python:
    Programming the way
    Guido
    indented it.
       - (originated with Skip Montanaro?)




More information about the Python-list mailing list