[issue20371] datetime.datetime.replace bypasses a subclass's __new__
Edward O added the comment: Here is a workaround for subclasses (2&3-compatible): --- start code --- class MyDate(datetime): @classmethod def fromDT(cls, d): """ :type d: datetime """ return cls(d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond, d.tzinfo) def replace(self, *args, **kw): """ :type other: datetime.timedelta :rtype: MyDate """ return self.fromDT(super(MyDate, self).replace(*args, **kw)) --- end code --- This is really a bug and not a misuse as datetime was specifically adapted to be subclassing-friendly. From a look at the (python) source, this seems to be the only bit that was forgotten. The real fix is as per yselivanov comment [and no, this has nothing to do with pickle or copy AFAIK] -- versions: +Python 3.4 ___ Python tracker <http://bugs.python.org/issue20371> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20371] datetime.datetime.replace bypasses a subclass's __new__
Changes by Edward O : -- nosy: +eddygeek ___ Python tracker <http://bugs.python.org/issue20371> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22297] 2.7 json encoding broken for enums
Edward O added the comment: The arguments for fixing: * int subclasses overriding str is a very common usecase for enums (so much so that it was added to stdlib in 3.4). * json supporting a standard type of a subsequent python version, though not mandatory, would be beneficial to Py2/Py3 compatibility. * fixing this cannot break existing code * the fix could theoretically be done to 3.0-3.3 if Ethan's argument is deemed important. -- status: pending -> open ___ Python tracker <http://bugs.python.org/issue22297> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange
Changes by Edward O : -- nosy: +BreamoreBoy ___ Python tracker <http://bugs.python.org/issue22294> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7434] general pprint rewrite
Changes by Edward O : -- nosy: +eddygeek ___ Python tracker <http://bugs.python.org/issue7434> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22297] 2.7 json encoding broken for enums
Changes by Edward O : -- title: json encoding broken for -> 2.7 json encoding broken for enums ___ Python tracker <http://bugs.python.org/issue22297> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22297] json encoding broken for
New submission from Edward O: _make_iterencode in python2.7/json/encoder.py encodes custom enum types incorrectly (the label will be printed without '"') because of these lines (line 320 in 2.7.6): elif isinstance(value, (int, long)): yield buf + str(value) in constract, _make_iterencode in python 3 explicitly supports the enum types: elif isinstance(value, int): # Subclasses of int/float may override __str__, but we still # want to encode them as integers/floats in JSON. One example # within the standard library is IntEnum. yield buf + str(int(value)) -- components: Library (Lib) messages: 226057 nosy: eddygeek priority: normal severity: normal status: open title: json encoding broken for type: behavior versions: Python 2.7 ___ Python tracker <http://bugs.python.org/issue22297> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange
Changes by Edward O : -- nosy: +benjamin.peterson ___ Python tracker <http://bugs.python.org/issue22294> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange
New submission from Edward O: This is a patch for issues similar to #16573 With this patch, the following new tests are now unchanged: r = dict(zip(s, range(len(s))), **d) r = len(filter(attrgetter('t'), self.a)) r = min(map(methodcaller('f'), self.a)) max(map(node.id, self.nodes)) + 1 if self.nodes else 0 reduce(set.union, map(f, self.a)) Note that as part of the patch, the range transformation now calls the generic in_special_context in addition to the customized one (which. I guess, should be removed, but I didn't dare). All existing tests pass, but the patterns used may not be strict enough, though I tried to stick to how it was done for other consuming calls. M Lib/lib2to3/fixer_util.py M Lib/lib2to3/fixes/fix_xrange.py M Lib/lib2to3/tests/test_fixers.py -- components: 2to3 (2.x to 3.x conversion tool) files: 2to3_more_consuming_calls.diff hgrepos: 271 keywords: patch messages: 226019 nosy: eddygeek priority: normal severity: normal status: open title: 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange type: enhancement versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5 Added file: http://bugs.python.org/file36495/2to3_more_consuming_calls.diff ___ Python tracker <http://bugs.python.org/issue22294> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22005] datetime.__setstate__ fails decoding python2 pickle
Edward O added the comment: The code works when using encoding='bytes'. Thanks Tim for the suggestion. So this is not a bug, but is there any sense in having encoding='ASCII' by default in pickle ? -- ___ Python tracker <http://bugs.python.org/issue22005> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com