Bruno Cauet added the comment:

Hi,
I feel like this behaviour does not only affect IntEnum & related but anything 
that inherits from int.

Example:
>>> class foo(int):
...     def __init__(self, value, base=10):
...         if value == 2:
...             raise ValueError("not that!!")
...         super(foo, self).__init__(value, base=base)
...
>>> x = foo.from_bytes(b"\2", "big")
>>> x
2
>>> type(x)
foo

2 solutions come to mind:
- always return an int, and not the type. deleting 
Objects/longobjects.c:4845,4866 does the job.
- instantiate the required type with the value as the (sole?) argument, 
correctly initializing the object to be returned. In Serhyi's example this 
results in x == AddressFamily.AF_UNIX. the same lines are concerned.

----------
nosy: +bru

_______________________________________
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