classification
Title: Accessor macros for PyDateTime_Delta members
Type: Stage: patch review
Components: Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2012-01-07 13:50 by amaury.forgeotdarc, last changed 2012-01-17 20:40 by amaury.forgeotdarc. This issue is now closed.

Files
File name Uploaded Description Edit
timedelta_macros.patch amaury.forgeotdarc, 2012-01-07 13:50
Messages (5)
msg150796 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-01-07 13:50
All objects of the datetime module have macros to access their properties, except timedelta.
This simple patch adds the macros PyDateTime_DELTA_GET_DAYS, PyDateTime_DELTA_GET_SECONDS, PyDateTime_DELTA_GET_MICROSECONDS; module developers are encouraged to use these instead of obj->seconds for example.

Motivation:
PyPy cannot easily expose PyDateTime_Delta fields because datetime is implemented as a pure Python module and it's difficult to rebuild a C structure from a heap type.
In PyPy these macros are actually functions, which do something similar to PyLong_AsLong(PyObject_GetAttrString(obj, "seconds")):
https://bitbucket.org/pypy/pypy/src/b67e65d709e1/pypy/module/cpyext/cdatetime.py#cl-235
msg151410 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-01-16 21:40
The macros should be named PyDelta_XXX, as PyDelta_Check and friend.
Otherwise, makes sense.
msg151411 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-01-16 21:43
I named them following the other accessor macros: PyDateTime_TIME_GET_HOUR(), even though the check function is named PyTime_Check().
Which inconsistency do you prefer? :)
msg151412 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-01-16 21:51
Ow. Then I don't mind :)
msg151486 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-01-17 20:39
New changeset 463acb73fd79 by Amaury Forgeot d'Arc in branch 'default':
Issue #13727: Add 3 macros to access PyDateTime_Delta members:
http://hg.python.org/cpython/rev/463acb73fd79
History
Date User Action Args
2012-01-17 20:40:18amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
2012-01-17 20:39:44python-devsetnosy: + python-dev
messages: + msg151486
2012-01-16 21:51:39pitrousetmessages: + msg151412
2012-01-16 21:43:32amaury.forgeotdarcsetmessages: + msg151411
2012-01-16 21:40:45pitrousetnosy: + pitrou
messages: + msg151410
2012-01-07 13:50:35amaury.forgeotdarccreate