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 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:23ethan.furmansetrecipients: + rhettinger, facundobatista, mark.dickinson, pitrou, vstinner, Arfrever, skrah, juggernaut, iyogeshjoshi
2016-05-08 15:50:22ethan.furmanlinkissue23640 messages
2016-05-07 23:21:08ethan.furmanunlinkissue23640 messages
2015-04-04 09:08:10ethan.furmansetrecipients: + ethan.furman, barry, eli.bendersky, serhiy.storchaka, bru
2015-04-04 09:08:10ethan.furmansetmessageid: <1428138490.56.0.797061084185.issue23640@psf.upfronthosting.co.za>
2015-04-04 09:08:10ethan.furmanlinkissue23640 messages
2015-04-04 09:08:10ethan.furmancreate