[Python-Dev] constant/enum type in stdlib (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Tue Nov 23 19:06:42 CET 2010
- Previous message: [Python-Dev] constant/enum type in stdlib
- Next message: [Python-Dev] constant/enum type in stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Le mardi 23 novembre 2010 à 12:57 -0500, Fred Drake a écrit :
On Tue, Nov 23, 2010 at 12:37 PM, Antoine Pitrou <solipsis at pitrou.net> wrote: > Enumerations aren't a type at all (they have no distinguishing > property).
In any given language, this may be true, or not. Whether they should be distinct in Python is core to the current discussion.
I meant "type" in the structural sense (hence the parenthesis). enums are just auto-generated constants. Since Python makes it trivial to generate sequential integers, there's no need for a specific "enum" construct.
Now you may argue that enums should be strongly-typed, but that would be a bit backwards given Python's preference for duck-typing.
From a backward-compatibility perspective, what makes sense depends on whether they're used to implement existing constants (socket.AFINET, etc.) or if they reserved for new features only.
It's not only backwards compatibility. New features relying on C APIs have to be able to map constants to the integers used in the C library. It would be much better if this were done naturally rather than through explicit conversion maps. (this really means subclassing int, if we don't want to complicate C-level code)
Regards
Antoine.
- Previous message: [Python-Dev] constant/enum type in stdlib
- Next message: [Python-Dev] constant/enum type in stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]