On 04/27/2013 09:01 AM, Guido van Rossum wrote: > > Hm... A lightbulb just went off. Objects representing both undecorated > and decorated methods have a __get__() method, courtesy of the > descriptor protocol. Maybe checking for that will work? It feels > Pythonic to me: it uses a corner of the language that most people > don't even know exists (*), but it produces the desired effect in > almost all cases that matter, the pattern is simple to describe and > easy to use without thinking about it, and for experts the rules are > completely clear, uncomplicated, and free of heuristics, so it is > possible to reason about corner cases. While this will certainly work, it means you can't have class variables that happen to be the same type as the enum -- so no int in an IntEnum, for example. The solution I like best is the helper class (called, originally enough, enum), and only those items get transformed: class Planet(IntEnum): MERCURY = enum(1) VENUS = enum(2) EARTH = enum(3) rough_pi = 3 # not transformed -- ~Ethan~
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