Message237887
| Author |
bru |
| Recipients |
barry, bru, eli.bendersky, ethan.furman, serhiy.storchaka |
| Date |
2015年03月11日.16:58:04 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1426093084.23.0.6121744571.issue23640@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|