Message251750
| Author |
serhiy.storchaka |
| Recipients |
barry, bru, eli.bendersky, facundobatista, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, skrah |
| Date |
2015年09月28日.07:21:22 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1443424882.86.0.103758083754.issue23640@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
There are similar issues with Decimal.from_float() (C implementation only), chain.from_iterable(), epoll.fromfd() and kqueue.fromfd(). All these alternative constructors don't call __new__ or __init__.
But float.fromhex() calls the constructor.
>>> import enum
>>> class M(float, enum.Enum):
... PI = 3.14
...
>>> M.PI
<M.PI: 3.14>
>>> M.fromhex((3.14).hex())
<M.PI: 3.14>
>>> M.fromhex((2.72).hex())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/enum.py", line 241, in __call__
return cls.__new__(cls, value)
File "/home/serhiy/py/cpython/Lib/enum.py", line 476, in __new__
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 2.72 is not a valid M
And this behavior looks correct to me. |
|