[Python-Dev] Enum Eccentricities (original) (raw)
Steven D'Aprano steve at pearwood.info
Mon Sep 23 17:16:23 CEST 2013
- Previous message: [Python-Dev] Enum Eccentricities
- Next message: [Python-Dev] Enum Eccentricities
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] Enum Eccentricities
- Next message: [Python-Dev] Enum Eccentricities
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]