-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to get tzinfo from a datetime instance in C API #74341
Comments
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! |
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. |
Any progress on this? |
So this bug is asking for two things:
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:
Please make sure to add tests to any PR you make. See the CapiTest case ( cpython/Lib/test/datetimetester.py Line 5914 in d68e0a8
(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) |
+1 for this. |
I have created PR 21633 to add these macros. Please consider taking a look. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: