Issue30155
Created on 2017-04-24 15:27 by atuining, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 21633 | merged | ZackerySpytz, 2020-07-27 01:44 | |
| Messages (7) | |||
|---|---|---|---|
| msg292230 - (view) | Author: Anthony Tuininga (atuining) * | Date: 2017-04-24 15:27 | |
Right now there is no documented way to create a datetime instance with a tzinfo instance. The documented macros all hard code the value Py_None for the tzinfo parameter. Using the PyObject_Call() method instead of the macro for creating a datetime instance is ~5x slower. In addition, there is no macro or method for getting the tzinfo from an existing datetime instance. Perhaps creating DATE_GET_TZINFO and TIME_GET_TZINFO would be acceptable? The enhancement 10381 (http://bugs.python.org/issue10381) would also be needed. I can provide a GitHub PR if that would be helpful. I first want to make sure that such an effort would be appreciated! |
|||
| msg321112 - (view) | Author: Paul Ganssle (p-ganssle) * ![]() |
Date: 2018-07-05 15:54 | |
Hmm. I never noticed this. In the past I have used the (undocumented) PyDateTimeAPI struct, which the official macros wrap. I'm not sure how official that struct is considering it doesn't show up in the documentation. I agree that it should be possible to construct TZ-aware datetimes using the official C API, so I guess the question is whether to add a bunch more macros or document the existing struct. |
|||
| msg361722 - (view) | Author: Anthony Tuininga (atuining) * | Date: 2020-02-10 21:22 | |
Any progress on this? |
|||
| msg361737 - (view) | Author: Paul Ganssle (p-ganssle) * ![]() |
Date: 2020-02-10 22:31 | |
So this bug is asking for two things: 1. An official accessor for the `tzinfo` component of an existing datetime, which I think is very reasonable in light of the fact that there are official accessors for all the other components of a datetime. 2. An official constructor for a timezone-aware datetime, which I think basically exists in the form of PyDatetime_CAPI->PyDateTimeAPI->DateTime_FromDateAndTime / ->DateTime_FromDateAndTimeAndFold, and we just need to document it. I think this is basically a separate issue, and I have opened #39604 to track it. I'm going to rename this bug to focus only on issue #1. I think we can accept a PR adding two new macros. I would suggest calling them: - PyDateTime_DATE_GET_TZINFO - PyDateTime_TIME_GET_TZINFO Please make sure to add tests to any PR you make. See the CapiTest case (https://github.com/python/cpython/blob/d68e0a8a165761604e820c8cb4f20abc735e717f/Lib/test/datetimetester.py#L5914) for examples. You may want to look at the git blame for a few of those tests to see the PRs that they were added in, since part of the tests are defined in a C file. (As an aside: I don't love that the accessor methods are not available on the struct, since all the "macro-only" code needs to be re-implemented in all other-language bindings. Since the accessors are already all macro-only, though, might as well keep with the tradition for now :P) |
|||
| msg374009 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2020-07-20 14:35 | |
> I'm going to rename this bug to focus only on issue #1. I think we can accept a PR adding two new macros. I would suggest calling them: > - PyDateTime_DATE_GET_TZINFO > - PyDateTime_TIME_GET_TZINFO +1 for this. |
|||
| msg374354 - (view) | Author: Zackery Spytz (ZackerySpytz) * ![]() |
Date: 2020-07-27 02:00 | |
I have created PR 21633 to add these macros. Please consider taking a look. |
|||
| msg377417 - (view) | Author: Paul Ganssle (p-ganssle) * ![]() |
Date: 2020-09-23 18:43 | |
New changeset 2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5 by Zackery Spytz in branch 'master': bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633) https://github.com/python/cpython/commit/2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:45 | admin | set | github: 74341 |
| 2020-10-21 19:51:20 | p-ganssle | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2020-09-23 18:43:53 | p-ganssle | set | messages: + msg377417 |
| 2020-07-27 02:00:41 | ZackerySpytz | set | messages:
+ msg374354 versions: + Python 3.10, - Python 3.9 |
| 2020-07-27 01:44:06 | ZackerySpytz | set | keywords:
+ patch nosy: + ZackerySpytz pull_requests:
+ pull_request20775 |
| 2020-07-20 14:35:33 | pitrou | set | nosy:
+ pitrou messages: + msg374009 |
| 2020-02-10 22:31:28 | p-ganssle | set | title: Add ability to get/set tzinfo on datetime instances in C API -> Add ability to get tzinfo from a datetime instance in C API stage: needs patch messages: + msg361737 versions: + Python 3.9, - Python 3.6 |
| 2020-02-10 21:22:03 | atuining | set | messages: + msg361722 |
| 2019-12-09 16:15:45 | belopolsky | set | dependencies: + Add timezone support to datetime C API |
| 2019-12-09 16:13:43 | vstinner | set | components: + C API |
| 2018-07-05 15:54:14 | p-ganssle | set | nosy:
+ p-ganssle messages: + msg321112 |
| 2017-04-29 15:56:14 | xiang.zhang | set | nosy:
+ belopolsky |
| 2017-04-24 16:35:31 | dlenski | set | nosy:
+ dlenski |
| 2017-04-24 15:27:26 | atuining | create | |

