[issue23640] int.from_bytes() is broken for subclasses

2016-05-12 Thread R. David Murray
R. David Murray added the comment: @eltoder: Ah, you are right, I was looking at the python version. There's an open issue about this, #20371, which indicates that the design decision was to support subclasses. Clearly I was remembering the conversation backward based on looking at the

[issue23640] int.from_bytes() is broken for subclasses

2016-05-12 Thread Antoine Pitrou
Changes by Antoine Pitrou : -- nosy: -pitrou ___ Python tracker ___ ___ Python-bugs-list

[issue23640] int.from_bytes() is broken for subclasses

2016-05-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Discussion on Python-Dev: http://comments.gmane.org/gmane.comp.python.devel/157649 . The conclusion is that alternate constructors should return an instance of the subclass, and either call constructor or use pickling machinery for creating an object in

[issue23640] int.from_bytes() is broken for subclasses

2016-05-12 Thread Roundup Robot
Roundup Robot added the comment: New changeset 0af15b8ef3b2 by Serhiy Storchaka in branch '3.5': Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses. https://hg.python.org/cpython/rev/0af15b8ef3b2 New changeset df14ea17a517 by Serhiy Storchaka in branch 'default':

[issue23640] int.from_bytes() is broken for subclasses

2016-05-11 Thread Eugene Toder
Eugene Toder added the comment: They sure do. Check the example in my comment, or if you prefer the source code, it's pretty clear as well: https://hg.python.org/cpython/file/fff0c783d3db/Modules/_datetimemodule.c#l2770 -- ___ Python tracker

[issue23640] int.from_bytes() is broken for subclasses

2016-05-11 Thread R. David Murray
R. David Murray added the comment: No, they do not return instances of the derived type, they return instances of the base type. This is an intentional design decision that has been discussed elsewhere (including, I think, somewhere in this tracker). -- nosy: +r.david.murray

[issue23640] int.from_bytes() is broken for subclasses

2016-05-11 Thread Eugene Toder
Eugene Toder added the comment: There's a similar issue with replace() methods on date/time/datetime classes. They create instances of derived types without calling derived __new__/__init__, thus potentially leaving those uninitialized. >>> from datetime import date >>> class D(date): ...

[issue23640] int.from_bytes() is broken for subclasses

2016-05-08 Thread Ethan Furman
Ethan Furman added the comment: With the patch: --> import enum --> class Huh(enum.IntEnum): ... blah = 2 ... --> Huh.blah.from_bytes(b'\04', 'big') Traceback (most recent call last): File "", line 1, in File "/home/ethan/source/python/issue23640/Lib/enum.py", line 222,

[issue23640] int.from_bytes() is broken for subclasses

2016-05-08 Thread Ethan Furman
Ethan Furman added the comment: I think the classmethod-as-constructor behavior is correct, so it's up to IntEnum (or EnumMeta, or foo, or ...), to work around the issue. -- ___ Python tracker

[issue23640] int.from_bytes() is broken for subclasses

2016-05-08 Thread Ethan Furman
Ethan Furman added the comment: 'from_bytes' is a classmethod. As such, it should return the same type as the class it is called on. If that wasn't the intent it would be a staticmethod instead. It is the responsibility of the subclass to override base class behavior, not the other way

[issue23640] int.from_bytes() is broken for subclasses

2016-05-07 Thread Ethan Furman
Changes by Ethan Furman : -- Removed message: http://bugs.python.org/msg237891 ___ Python tracker ___

[issue23640] int.from_bytes() is broken for subclasses

2016-05-07 Thread Ethan Furman
Changes by Ethan Furman : -- Removed message: http://bugs.python.org/msg240053 ___ Python tracker ___

[issue23640] int.from_bytes() is broken for subclasses

2016-05-07 Thread Ethan Furman
Changes by Ethan Furman : -- Removed message: http://bugs.python.org/msg239619 ___ Python tracker ___

[issue23640] int.from_bytes() is broken for subclasses

2016-05-07 Thread Ethan Furman
Ethan Furman added the comment: Not sure what I was thinking at the time, but several of my comments were supportive of `classmethod`s not calling subclass' __new__; I actually do not think that, and am +1 on the patch. -- nosy: +ethan.furman ___

[issue23640] int.from_bytes() is broken for subclasses

2015-10-02 Thread ashutosh
ashutosh added the comment: hi i am ashutosh. I am running kubuntu 14.04. before applying the patch. It failed in 2 test i.e test___all__ test_re After applying patch. It again gave me 2 error test___all__ test_re So,it worked for me. -- nosy: +singh_jug

[issue23640] int.from_bytes() is broken for subclasses

2015-10-02 Thread Yogesh Joshi
Yogesh Joshi added the comment: I applied patch to module and ran all the tested on Mac Os El Captain, only 4 tests were failing with or without applying patch, following are the tests failing: test___all__ test_calendar test_re test_socket -- nosy: +iyogeshjoshi

[issue23640] int.from_bytes() is broken for subclasses

2015-09-29 Thread STINNER Victor
STINNER Victor added the comment: 0002-int.from_bytes-calls-constructor-for-subclasses.patch looks good to me, but see my review on Rietveld for 2 minor comments. -- nosy: +haypo ___ Python tracker

[issue23640] int.from_bytes() is broken for subclasses

2015-09-29 Thread Stefan Krah
Stefan Krah added the comment: > There are similar issues with Decimal.from_float() (C implementation only), > chain.from_iterable(), epoll.fromfd() and kqueue.fromfd(). All these > alternative constructors don't call __new__ or __init__. Could you create new issues? I need a summary. :)

[issue23640] int.from_bytes() is broken for subclasses

2015-09-28 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis : -- nosy: +Arfrever ___ Python tracker ___

[issue23640] int.from_bytes() is broken for subclasses

2015-09-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There are similar issues with Decimal.from_float() (C implementation only), chain.from_iterable(), epoll.fromfd() and kqueue.fromfd(). All these alternative constructors don't call __new__ or __init__. But float.fromhex() calls the constructor. >>> import

[issue23640] int.from_bytes() is broken for subclasses

2015-09-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Here is simplified Bruno's patch with additional tests for float, int, bool and enum. But I'm not sure that correct solution is so simple. -- Added file: http://bugs.python.org/file40606/0002-int.from_bytes-calls-constructor-for-subclasses.patch

[issue23640] int.from_bytes() is broken for subclasses

2015-07-21 Thread Ethan Furman
Changes by Ethan Furman et...@stoneleaf.us: -- assignee: ethan.furman - nosy: -ethan.furman title: Enum.from_bytes() is broken - int.from_bytes() is broken for subclasses ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23640