Mark Dickinson added the comment:

> Why?  I've never encountered this recommendation before.  x.__float__() > 
> would be clearer, IMO.

Hmm;  it would be better if I engaged by brain before commenting.  I guess the 
point is that type(x).__float__(x) better matches the behaviour of the builtin 
float:


>>> class A:
...     def __float__(self): return 42.0
... 
>>> a = A()
>>> a.__float__ = lambda: 1729.0
>>> 
>>> float(a)
42.0
>>> a.__float__()
1729.0
>>> type(a).__float__(a)
42.0


When you get around to tests, it would be nice to have a test for this 
behaviour, just so that someone who comes along and wonders the code is written 
this way gets an immediate test failure when they try to incorrectly "simplify" 
it.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18606>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to