Message251750
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. |
|
Date |
User |
Action |
Args |
2015-09-28 07:21:23 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, barry, rhettinger, facundobatista, mark.dickinson, pitrou, eli.bendersky, skrah, bru |
2015-09-28 07:21:22 | serhiy.storchaka | set | messageid: <1443424882.86.0.103758083754.issue23640@psf.upfronthosting.co.za> |
2015-09-28 07:21:22 | serhiy.storchaka | link | issue23640 messages |
2015-09-28 07:21:22 | serhiy.storchaka | create | |
|