any interest in type-scoped static constants?

Paul Miller paul at fxtech.com
Sun Mar 11 16:10:48 CET 2001


If I write an extension type that mirrors the functionality of a C++
class, and the C++ has static constants within its scope, I can do this
in C++:

	Point p = Point::ZERO;

Where ZERO is defined as:

	class Point
	{
		static Point ZERO = Point(0, 0);
	};

If I create an extension type for Point, I can't do this:

	p = Point.ZERO

But I'd like to.

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?

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.



More information about the Python-list mailing list