Serhiy Storchaka added the comment:

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.

----------
nosy: +facundobatista, mark.dickinson, rhettinger, skrah

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

Reply via email to