Message240053
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. |
|
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 | |
|