Message240053
| Author |
ethan.furman |
| Recipients |
Arfrever, barry, bru, eli.bendersky, ethan.furman, facundobatista, iyogeshjoshi, juggernaut, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, skrah, vstinner |
| Date |
2015年04月04日.09:08:10 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1428138490.56.0.797061084185.issue23640@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
With the patch:
--> import enum
--> class Huh(enum.IntEnum):
... blah = 2
...
--> Huh.blah.from_bytes(b'04円', 'big')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ethan/source/python/issue23640/Lib/enum.py", line 222, in __call__
return cls.__new__(cls, value)
File "/home/ethan/source/python/issue23640/Lib/enum.py", line 457, in __new__
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 4 is not a valid Huh
This is not the correct behavior. An IntEnum should act like an int, and in cases where it can't and still be an IntEnum, it becomes an int. But this behavior is Enum specific, and I would not expect other int subclasses to need or want that behavior.
Also, in cases where class methods are alternate constructors there is no requirement that they go through the main __new__/__init__ constructors to do their job.
In other words, if IntEnum.from_bytes (which is inherited) is not behaving correctly, it is up to IntEnum to fix it -- it is not the job of int, and this is not a bug in int. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2016年05月08日 15:50:23 | ethan.furman | set | recipients:
+ rhettinger, facundobatista, mark.dickinson, pitrou, vstinner, Arfrever, skrah, juggernaut, iyogeshjoshi |
| 2016年05月08日 15:50:22 | ethan.furman | link | issue23640 messages |
| 2016年05月07日 23:21:08 | ethan.furman | unlink | issue23640 messages |
| 2015年04月04日 09:08:10 | ethan.furman | set | recipients:
+ ethan.furman, barry, eli.bendersky, serhiy.storchaka, bru |
| 2015年04月04日 09:08:10 | ethan.furman | set | messageid: <1428138490.56.0.797061084185.issue23640@psf.upfronthosting.co.za> |
| 2015年04月04日 09:08:10 | ethan.furman | link | issue23640 messages |
| 2015年04月04日 09:08:10 | ethan.furman | create |
|