[Tutor] pure symbol -- __subtype__
steve at pearwood.info
Thu Feb 18 12:08:22 CET 2010
On Thu, 18 Feb 2010 08:13:33 pm spir wrote:
> I was lately implementing a kind of "pure symbol" type. What I call
> pure symbols is these kinds of constants that refer to pure "idea",
> so that they have no real obvious value. We usually _arbitrarily_
> give them as value an int, a string, a boolean, an empty object:
If you are interested in this, there are various modules on PyPI for
them, such as:
which probably does everything you want.
Unfortunately any enum solution is going to be rather heavyweight
compared to (say) Pascal, which can simply give each enum an integer
value and have the compiler enforce separation of types. (In other
words, all the heavy complexity is in the compiler rather than the
If you want a lightweight solution, just use constant strings or
> Actually, what I need is a kind of __subtype__ magic method that acts
> for subtyping the same way __init__ does for instanciation.
That's what metaclasses are for.
More information about the Tutor