
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2017-12-21 21:54 byp-ganssle, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 4993 | merged | p-ganssle,2017-12-23 20:02 | |
| Messages (2) | |||
|---|---|---|---|
| msg308908 -(view) | Author: Paul Ganssle (p-ganssle)*![]() | Date: 2017-12-21 21:54 | |
In writing some tests for the alternate date constructors as part of my PR forissue 32403 (https://bugs.python.org/issue32403), I noticed that for `datetime`, the `fromtimestamp` bypasses the `__new__` call on the subclass: from datetime import datetime args = (2003, 4, 14) ts =1050292800.0 # Equivalent timestamp d_ord = 731319 # Equivalent ordinal date class DatetimeSubclass(datetime): def __new__(cls, *args, **kwargs): result = datetime.__new__(cls, *args, **kwargs) result.extra = 7 return result base_d = DatetimeSubclass(*args) assert isinstance(base_d, DatetimeSubclass) # Passes assert base_d.extra == 7 # Passes ord_d = DatetimeSubclass.fromordinal(d_ord) assert isinstance(ord_d, DatetimeSubclass) # Passes assert ord_d.extra == 7 # Passes ts_d = DatetimeSubclass.fromtimestamp(ts) assert isinstance(ts_d, DatetimeSubclass) # Passes assert ts_d.extra == 7 # FailsReplacing `datetime` with `date` in the above code we don't get a failure, but with `datetime`, it fails with: AttributeError: 'DatetimeSubclass' object has no attribute 'extra'Regardless of the status of 32403, I think this should be fixed (though I can try to fix them both at the same time). | |||
| msg310100 -(view) | Author: Alexander Belopolsky (belopolsky)*![]() | Date: 2018-01-16 18:06 | |
New changeset9f1b7b93f5f0ef589e7b272e127cacf4ce5d23f1 by Alexander Belopolsky (Paul Ganssle) in branch 'master':bpo-32403: Faster date and datetime constructors (#4993)https://github.com/python/cpython/commit/9f1b7b93f5f0ef589e7b272e127cacf4ce5d23f1 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:55 | admin | set | github: 76585 |
| 2018-01-16 18:06:34 | belopolsky | set | status: open -> closed resolution: fixed messages: +msg310100 stage: patch review -> resolved |
| 2017-12-23 20:02:39 | p-ganssle | set | keywords: +patch stage: patch review pull_requests: +pull_request4882 |
| 2017-12-21 21:54:13 | p-ganssle | create | |