[docs] Code, test, and doc review for PEP-0435 Enum (issue 17947)

eliben at gmail.com eliben at gmail.com
Sun May 12 15:02:00 CEST 2013


http://bugs.python.org/review/17947/diff/8105/Lib/enum.py
File Lib/enum.py (right):

http://bugs.python.org/review/17947/diff/8105/Lib/enum.py#newcode18
Lib/enum.py:18: class StealthProperty():
On 2013/05/12 14:47:00, stoneleaf wrote:
> On 2013/05/10 16:46:19, berkerpeksag wrote:
> > Is there a reason not to write `class StealthProperty:` (without the
brackets)
> > here?
> 
> I just always use them.

Remove them - they're not needed in Python 3 and their presence is
confusing.

http://bugs.python.org/review/17947/diff/8105/Lib/enum.py#newcode84
Lib/enum.py:84: if key[:2] == key[-2:] == '__' or hasattr(something,
'__get__'):
On 2013/05/12 14:47:00, stoneleaf wrote:
> On 2013/05/10 16:02:43, eli.bendersky wrote:
> > parenthesize the parts of the or
> 
> like:
> 
> if (key[:2] == key[-2:] == '__') or (hasattr(something, '__get__')):
> 
> ?
> 
> Why?

Because it's easier to read. The problem is that you have multiple
operators there. If you encapsulate the dunder check in a method, you
can keep it without the parens.

http://bugs.python.org/review/17947/diff/8105/Lib/enum.py#newcode280
Lib/enum.py:280: return cls._enum_map.copy()
On 2013/05/12 14:47:01, stoneleaf wrote:
> On 2013/05/10 16:02:43, eli.bendersky wrote:
> > why copy?
> 
> If we return the actual map, and it gets modified, our Enum class just
got
> destroyed (or at least corrupted).

That's tough life, no doubt ;-), but appropriate in Python. You can do
much worse things to objects and classes - we don't do safeguards here.
Consenting adults.

http://bugs.python.org/review/17947/


More information about the docs mailing list