[Python-ideas] PEP for enum library type?

Richard Oudkerk shibturn at gmail.com
Thu Feb 14 12:34:23 CET 2013


On 14/02/2013 12:57am, Jan Kaliszewski wrote:
> and maybe also:
>
>      class Color(Enum):
>          # 0     1     2     3
>          RED, GREEN, BLUE, YELLOW, *end = seq()
>
>      class Color(Enum):
>          # 3     4     5     6
>          RED, GREEN, BLUE, YELLOW, *end = seq(3)
>
>      class Flag(Enum):
>          # 1    2    4    8    16
>          FOO, BAR, BAZ, BOO, SPAM, *end = flags()
>
> (yes, it *is* possible to implement it without playing with stack
> frames...)

Are seq and flags infinite generators/iterators?  If so then this won't 
work because end will be a *list* containing the contents of the tail of 
the iterator.

 >>> def gen():
...   i = 0
...   while True:
...     yield i
...     i += 1
...
 >>> a, b, *end = gen()
<Hangs, consuming more and more memory>

-- 
Richard




More information about the Python-ideas mailing list