<br><br><div class="gmail_quote">On 27 July 2011 12:57, Giampaolo Rodolà <span dir="ltr"><<a href="mailto:g.rodola@gmail.com">g.rodola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="im">2011/7/25 Barry Warsaw <span dir="ltr"><<a href="mailto:barry@python.org" target="_blank">barry@python.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Jul 24, 2011, at 05:33 PM, Guido van Rossum wrote:<br>
<br>
>For enums, I think we should just pick a solution. I'm in favor of<br>
>Barry Warsaw's version, flufl.enum.<br>
<br>
</div>Thanks! I would be quite happy to see the library pulled into the stdlib, and<br>
I'd be willing to maintain a backward compatible standalone version for older<br>
Pythons.<br>
<br>
For me, the API has been quite stable. The last thing I added was Michael<br>
Foord's make_enum() contribution, and PJE's fix for pickling. I haven't felt<br>
a burning need to add anything else really in quite some time.<br></blockquote><div><br></div><div><br></div></div><div><div class="im"><div> >>> from flufl.enum import Enum</div></div><div> >>> class Colors(Enum):</div>
<div> ... red = 1</div>
<div> ... green = 2</div><div> ... blue = 3</div></div><div><br></div><div>What I find uncomfortable with this is the extra "Colors" name space.</div><div>
Say we change all the socket module constants to make use of this, what will we have?</div>
<div><br>>>> socket.AF_INET</div><div><EnumValue: Constants.AF_INET [int=2]></div><div><br></div><div>...and:</div><div><br></div><div>>>> socket.Constants.AF_INET</div><div><EnumValue: Constants.AF_INET [int=2]></div>
<div><br></div><div>...? Is that correct?</div><div><br></div></div></blockquote><div><br>It could be. We can do what what we want.<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div></div><div>Also:</div><div><br></div><div><div>>>> socket.AF_INET</div><div><EnumValue: Constants.AF_INET [int=2]></div>
</div><div>>>> socket.AF_INET == 2</div><div>False</div><div>>>></div><div><br></div><div>This shouldn't be underestimated: I've seen code comparing against plain integers rather than constants more than once, and that code would eventually break.</div>
</div></blockquote><div><br>Immediately break. I agree that this is a problem - new constants should compare equal to their old values if we use them in the standard library.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote">
<div>Personally I've never felt the need of any kind of "enum" type. </div><div>On the other hand I would welcome a "named constant" type of some kind but IMO, it should remain a base integer and provide just a minimal extra layer of usability, such as:</div>
</div></blockquote><div><br><br>Sure. Providing grouping for named constants for simpler defining of them is a nice feature though. We should *not* add enums but instead should have named constants and grouped constants.<br>
<br>Michael<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote">
<div><br></div><div>class constant(int):</div><div><div> """A constant type; overrides base int to provide a useful name on str()."""</div>
<div><br></div><div> def __new__(cls, value, name, doc=None):</div><div> inst = super(constant, cls).__new__(cls, value)</div><div> inst._name = name</div><div> if doc is not None:</div><div> inst.__doc__ = doc</div>
<div> return inst</div><div><br></div><div> def __str__(self):</div><div> return self._name</div><div><br></div><div>>>> STATUS_RUNNING = constant(0, "running")</div><div>>>> STATUS_RUNNING</div>
<div>0</div><div>>>> str(STATUS_RUNNING)</div><div>"running"</div><div>>>></div></div><div><br></div><div><br></div><div>In summary, I'm -1 about including this into the stdlib and change all the stdlib constants in accordarce.</div>
<div><br></div><div>My 2 cents.</div><div><br></div><div><br></div><div>--- Giampaolo</div><div><a href="http://code.google.com/p/psutil/downloads/list" target="_blank">http://code.google.com/p/pyftpdlib/</a></div>
<div><a href="http://code.google.com/p/psutil/downloads/list" target="_blank">http://code.google.com/p/psutil/</a></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><pre cols="72"><a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br><br>May you do good and not evil<br>May you find forgiveness for yourself and forgive others<br>
May you share freely, never taking more than you give.<br>-- the sqlite blessing <a href="http://www.sqlite.org/different.html" target="_blank">http://www.sqlite.org/different.html</a></pre>
<br>