<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 3, 2013 at 6:34 AM, Greg Ewing <span dir="ltr"><<a href="mailto:greg.ewing@canterbury.ac.nz" target="_blank">greg.ewing@canterbury.ac.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Barry Warsaw wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I still don't get it why this is an issue though, or at least why this is<br>
different than any other getattr on any other class,<br>
</blockquote>
<br></div>
It's not a problem that getattr() has this behaviour.<br>
What I'm questioning is the idea that getattr() should<br>
be the only provided way of doing a name->enum lookup,<br>
because that will require everyone to do extra checks<br>
to ensure safety.<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>I'm just curious what it is about enums that sets everyone on a "let's make things safer" path. Python is about duck typing, it's absolutely "unsafe" in the static typing sense, in the most fundamental ways imaginable. When programmatically invoking a method on a class (say some sort of RPC), we don't check that the class is of the correct type. We invoke a method, and if it quacks, that's a good enough duck. If it was actually the wrong class, something will break later. EAFP Is a central Python tenet, whether we like it or not. If one looks for static guarantees, Python surely shouldn't be the preferred language, no?<br>
<br></div><div>And concretely, how is this case different from any programmatic attribute access in Python objects? You can pass dunders to getattr() and it probably wasn't what you meant, but Python does not do this type checking for you. Why is an Enum different than any other class?<br>
</div><div><br></div><div>Eli<br><br><br></div></div><br></div></div>