This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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.
History
Date User Action Args
2015-09-28 07:21:23serhiy.storchakasetrecipients: + serhiy.storchaka, barry, rhettinger, facundobatista, mark.dickinson, pitrou, eli.bendersky, skrah, bru
2015-09-28 07:21:22serhiy.storchakasetmessageid: <1443424882.86.0.103758083754.issue23640@psf.upfronthosting.co.za>
2015-09-28 07:21:22serhiy.storchakalinkissue23640 messages
2015-09-28 07:21:22serhiy.storchakacreate