summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2020-05-16 14:02:59 (GMT)
committerGitHub <noreply@github.com>2020-05-16 14:02:59 (GMT)
commit1b97b9b0ad9a2ff8eb5c8f2e2e7c2aec1d13a330 (patch)
treee4e0db3789e402a65ad817f0a17375b756d3e251 /Doc
parentaa92a7cf210c98ad94229f282221136d846942db (diff)
downloadcpython-1b97b9b0ad9a2ff8eb5c8f2e2e7c2aec1d13a330.zip
cpython-1b97b9b0ad9a2ff8eb5c8f2e2e7c2aec1d13a330.tar.gz
cpython-1b97b9b0ad9a2ff8eb5c8f2e2e7c2aec1d13a330.tar.bz2
bpo-24416: Return named tuple from date.isocalendar() (GH-20113)
{date, datetime}.isocalendar() now return a private custom named tuple object IsoCalendarDate rather than a simple tuple. In order to leave IsocalendarDate as a private class and to improve what backwards compatibility is offered for pickling the result of a datetime.isocalendar() call, add a __reduce__ method to the named tuples that reduces them to plain tuples. (This is the part of this PR most likely to cause problems — if it causes major issues, switching to a strucseq or equivalent would be prudent). The pure python implementation of IsoCalendarDate uses positional-only arguments, since it is private and only constructed by position anyway; the equivalent change in the argument clinic on the C side would require us to move the forward declaration of the type above the clinic import for whatever reason, so it seems preferable to hold off on that for now. bpo-24416: https://bugs.python.org/issue24416 Original PR by Dong-hee Na with only minor alterations by Paul Ganssle. Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/datetime.rst20
-rw-r--r--Doc/whatsnew/3.9.rst7
2 files changed, 19 insertions, 8 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 22ecbb5..4daf5df 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -670,7 +670,8 @@ Instance methods:
.. method:: date.isocalendar()
- Return a 3-tuple, (ISO year, ISO week number, ISO weekday).
+ Return a :term:`named tuple` object with three components: ``year``,
+ ``week`` and ``weekday``.
The ISO calendar is a widely used variant of the Gregorian calendar. [#]_
@@ -682,11 +683,14 @@ Instance methods:
For example, 2004 begins on a Thursday, so the first week of ISO year 2004
begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 2004::
- >>> from datetime import date
- >>> date(2003, 12, 29).isocalendar()
- (2004, 1, 1)
- >>> date(2004, 1, 4).isocalendar()
- (2004, 1, 7)
+ >>> from datetime import date
+ >>> date(2003, 12, 29).isocalendar()
+ datetime.IsoCalendarDate(year=2004, week=1, weekday=1)
+ >>> date(2004, 1, 4).isocalendar()
+ datetime.IsoCalendarDate(year=2004, week=1, weekday=7)
+
+ .. versionchanged:: 3.9
+ Result changed from a tuple to a :term:`named tuple`.
.. method:: date.isoformat()
@@ -1397,8 +1401,8 @@ Instance methods:
.. method:: datetime.isocalendar()
- Return a 3-tuple, (ISO year, ISO week number, ISO weekday). The same as
- ``self.date().isocalendar()``.
+ Return a :term:`named tuple` with three components: ``year``, ``week``
+ and ``weekday``. The same as ``self.date().isocalendar()``.
.. method:: datetime.isoformat(sep='T', timespec='auto')
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index cbddbb4..bddb710 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -281,6 +281,13 @@ Add :func:`curses.get_escdelay`, :func:`curses.set_escdelay`,
:func:`curses.get_tabsize`, and :func:`curses.set_tabsize` functions.
(Contributed by Anthony Sottile in :issue:`38312`.)
+datetime
+--------
+The :meth:`~datetime.date.isocalendar()` of :class:`datetime.date`
+and :meth:`~datetime.datetime.isocalendar()` of :class:`datetime.datetime`
+methods now returns a :func:`~collections.namedtuple` instead of a :class:`tuple`.
+(Contributed by Dong-hee Na in :issue:`24416`.)
+
fcntl
-----