homepage

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 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.
History
Date User Action Args
2015年03月11日 16:58:04brusetrecipients: + bru, barry, eli.bendersky, ethan.furman, serhiy.storchaka
2015年03月11日 16:58:04brusetmessageid: <1426093084.23.0.6121744571.issue23640@psf.upfronthosting.co.za>
2015年03月11日 16:58:04brulinkissue23640 messages
2015年03月11日 16:58:04brucreate

AltStyle によって変換されたページ (->オリジナル) /