Showing content from http://mail.python.org/pipermail/python-dev/attachments/20130223/7ea09a62/attachment.html below:
<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Feb 23, 2013 at 9:04 AM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="im">On Sat, 23 Feb 2013 08:27:50 -0800<br>
Eli Bendersky <<a href="mailto:eliben@gmail.com">eliben@gmail.com</a>> wrote:<br>
> > See also <a href="http://bugs.python.org/issue16801#msg178542" target="_blank">http://bugs.python.org/issue16801#msg178542</a> for another use<br>
> > case for named values.<br>
> ><br>
> > I've seen an awful lot of code that uses global variables or class<br>
> > attributes primarily to get name validation on constant values, and I<br>
> > think all of that code would be a prime candidate for using Named Values.<br>
> > Some of them are also enum-like, but many of them are not. So I'm with<br>
> > Nick on this one.<br>
><br>
> Any suggestions for places in the stdlib where enums could come useful will<br>
> be most welcome<br>
<br>
</div>The constants in the os module (os.SEEK_SET, etc.).<br>
The constants in the socket module (socket.AF_INET, etc.).<br>
And so on :-)</div></blockquote><div><br> Hmm, constants such as os.SEEK_* which serve as *inputs* to stdlib rather than outputs can actually be a good candidate for enum without worrying about backwards compatibility.<br>
<br></div><div>The reason I make the *input* vs. *output* distinction, is that for stdlib code that returns values, the user may rely on their numeric values and if we switch to enum code will break. However, for os.SEEK_* this is not the case. Thee can be aliases for enums:<br>
<br></div><div>class SeekKind(Enum):<br></div><div> SEEK_SET = 0<br></div><div> SEEK_CUR = 1<br></div><div> SEEK_END = 2<br><br></div><div>SEEK_SET = SeekKind.SEEK_SET<br>...<br><br></div><div>lseek() can be changed to call 'int' on its input, and now os.SEEK_* gain useful string representations when printed. <br>
<br></div><div>Thoughts?<br><br>Eli<br><br></div></div><br><br></div></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4