[Python-Dev] Enum Eccentricities
Steven D'Aprano
steve at pearwood.info
Mon Sep 23 17:16:23 CEST 2013
On Mon, Sep 23, 2013 at 07:53:00AM -0700, Guido van Rossum wrote:
> there is no rule that because you can
> access something on the class you should be able to access it on the
> instance. Try asking an instance for its class's __mro__ or __bases__.
It might not be a rule, but it's certainly the norm. I reckon that class
attributes that aren't accessible from the instance are significantly
more surprising than Color.red.blue.
I know I'm in a minority here, but Color.red.blue seems obvious and
straightforward to me. The fact that it doesn't work surprises me. Given
that
instance = Color.red
assert isinstance(instance, Color) # well of course it is
assert hasattr(Color, "blue")
I would expect instance.blue to work, and I'm completely at a loss as to
how Enum has managed to prevent it.
--
Steven
More information about the Python-Dev
mailing list