Message237887
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. |
|
Date |
User |
Action |
Args |
2015-03-11 16:58:04 | bru | set | recipients:
+ bru, barry, eli.bendersky, ethan.furman, serhiy.storchaka |
2015-03-11 16:58:04 | bru | set | messageid: <1426093084.23.0.6121744571.issue23640@psf.upfronthosting.co.za> |
2015-03-11 16:58:04 | bru | link | issue23640 messages |
2015-03-11 16:58:04 | bru | create | |
|