[Python-Dev] Enum Eccentricities (original) (raw)
Chris Lambacher chris at kateandchris.net
Mon Sep 23 15:45:46 CEST 2013
- Previous message: [Python-Dev] Enum Eccentricities
- Next message: [Python-Dev] Enum Eccentricities
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Sep 22, 2013 at 10:41 PM, Zero Piraeus <z at etiol.net> wrote:
I may be misunderstanding the use case given in the issue,
To clarify the use case, since it is my bug, this is so that the enum values are always available for comparison. The exact use case is in Django templates where a value comes from the database. If you want to compare you either have to use class which I would say is a code smell, or you have to provide the Enum class. The code we are using for this is open source http://github.com/tindie/django-tidyenum. An example of how this will be used in practice is:
{% if object.state == object.state.completed %}
some html
{% endif %}
but it seems to me that having to use
Color.red.class.blue (what is being complained about in the issue), while not exactly pretty, makes a lot more semantic sense than Color.red.blue ... which is just bizarre.
Any more bizarre than any other class that has properties of it's own type?
a = 0
a.real.numerator.real.numerator
It is only weird because we are not used to seeing classes where the properties are instances of the class. I am not a core developer, but I have been programming in Python for more than 10 years, and I (and the other similarly experienced developers I work with) found that not having access to the class level properties was weird (yes I am aware that they are not actually class level properties but everywhere else Enum works hard to make it look like they are. See for instance the dir method: http://hg.python.org/cpython/file/ed011b0d7daf/Lib/enum.py#l242).
-Chris
-- Christopher Lambacher chris at kateandchris.net -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130923/91305d45/attachment.html>
- Previous message: [Python-Dev] Enum Eccentricities
- Next message: [Python-Dev] Enum Eccentricities
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]