From 4e284ac0c51fbed4b6c2e22b02001b23efe8ccf2 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Thu, 2 Mar 2017 20:11:17 +0100 Subject: [PATCH 1/4] bpo-27200: fix faq/programming and datetime --- Doc/conf.py | 1 + Doc/faq/programming.rst | 4 ++-- .../{tzinfo-examples.py => tzinfo_examples.py} | 0 Doc/library/datetime.rst | 13 ++++++++++--- 4 files changed, 13 insertions(+), 5 deletions(-) rename Doc/includes/{tzinfo-examples.py => tzinfo_examples.py} (100%) diff --git a/Doc/conf.py b/Doc/conf.py index 18aebb68a8d8dfc..c1c2472a19630a0 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -8,6 +8,7 @@ import sys, os, time sys.path.append(os.path.abspath('tools/extensions')) +sys.path.append(os.path.abspath('includes')) # General configuration # --------------------- diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 9c5e20dcadf5a07..d9bdb21e79ac668 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1849,7 +1849,7 @@ containing statements like :: will continue to work with the old version of the imported objects. If the module contains class definitions, existing class instances will *not* be updated to use the new class definition. This can result in the following -paradoxical behaviour: +paradoxical behaviour:: >>> import importlib >>> import cls @@ -1860,7 +1860,7 @@ paradoxical behaviour: False The nature of the problem is made clear if you print out the "identity" of the -class objects: +class objects:: >>> hex(id(c.__class__)) '0x7352a0' diff --git a/Doc/includes/tzinfo-examples.py b/Doc/includes/tzinfo_examples.py similarity index 100% rename from Doc/includes/tzinfo-examples.py rename to Doc/includes/tzinfo_examples.py diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index c9318557f5c8269..2e2722b6d30e4c1 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1221,7 +1221,7 @@ Instance methods: >>> from datetime import datetime - >>> datetime.now().isoformat(timespec='minutes') + >>> datetime.now().isoformat(timespec='minutes') # doctest: +SKIP '2002-12-25T00:00' >>> dt = datetime(2015, 1, 1, 12, 30, 59, 0) >>> dt.isoformat(timespec='microseconds') @@ -1781,9 +1781,11 @@ There is one more :class:`tzinfo` method that a subclass may wish to override: else: return dt -Example :class:`tzinfo` classes: +In the following :download:`tzinfo_example.py +<../includes/tzinfo_examples.py>` file there are some examples of +:class:`tzinfo` classes: -.. literalinclude:: ../includes/tzinfo-examples.py +.. literalinclude:: ../includes/tzinfo_examples.py Note that there are unavoidable subtleties twice per year in a :class:`tzinfo` subclass accounting for both standard and daylight time, at the DST transition @@ -1804,6 +1806,10 @@ When DST starts (the "start" line), the local wall clock leaps from 1:59 to ``astimezone(Eastern)`` won't deliver a result with ``hour == 2`` on the day DST begins. For example, at the Spring forward transition of 2016, we get +.. doctest:: + + >>> from datetime import datetime, timezone + >>> from tzinfo_examples import HOUR, Eastern >>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc) >>> for i in range(4): ... u = u0 + i*HOUR @@ -1826,6 +1832,7 @@ hours into the same local hour then. In the Eastern example, UTC times of the form 5:MM and 6:MM both map to 1:MM when converted to Eastern, but earlier times have the :attr:`~datetime.fold` attribute set to 0 and the later times have it set to 1. For example, at the Fall back transition of 2016, we get +.. doctest:: >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc) >>> for i in range(4): From c5244949819a351100dd5840ec67a8b95f8dd5b9 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Thu, 2 Mar 2017 20:46:57 +0100 Subject: [PATCH 2/4] bpo-27200: fix a typo in the file name --- Doc/library/datetime.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index 2e2722b6d30e4c1..1224b5180a930fb 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1781,7 +1781,7 @@ There is one more :class:`tzinfo` method that a subclass may wish to override: else: return dt -In the following :download:`tzinfo_example.py +In the following :download:`tzinfo_examples.py <../includes/tzinfo_examples.py>` file there are some examples of :class:`tzinfo` classes: From b00827344d6761b3c821ecf70bc7c5790295d8fd Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Thu, 2 Mar 2017 20:56:37 +0100 Subject: [PATCH 3/4] fix-bpo-27200: blank line before doctest + indentation --- Doc/library/datetime.rst | 45 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index 1224b5180a930fb..c1ef1d2a78417e8 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1808,18 +1808,18 @@ begins. For example, at the Spring forward transition of 2016, we get .. doctest:: - >>> from datetime import datetime, timezone - >>> from tzinfo_examples import HOUR, Eastern - >>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc) - >>> for i in range(4): - ... u = u0 + i*HOUR - ... t = u.astimezone(Eastern) - ... print(u.time(), 'UTC =', t.time(), t.tzname()) - ... - 05:00:00 UTC = 00:00:00 EST - 06:00:00 UTC = 01:00:00 EST - 07:00:00 UTC = 03:00:00 EDT - 08:00:00 UTC = 04:00:00 EDT + >>> from datetime import datetime, timezone + >>> from tzinfo_examples import HOUR, Eastern + >>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc) + >>> for i in range(4): + ... u = u0 + i*HOUR + ... t = u.astimezone(Eastern) + ... print(u.time(), 'UTC =', t.time(), t.tzname()) + ... + 05:00:00 UTC = 00:00:00 EST + 06:00:00 UTC = 01:00:00 EST + 07:00:00 UTC = 03:00:00 EDT + 08:00:00 UTC = 04:00:00 EDT When DST ends (the "end" line), there's a potentially worse problem: there's an @@ -1832,18 +1832,19 @@ hours into the same local hour then. In the Eastern example, UTC times of the form 5:MM and 6:MM both map to 1:MM when converted to Eastern, but earlier times have the :attr:`~datetime.fold` attribute set to 0 and the later times have it set to 1. For example, at the Fall back transition of 2016, we get + .. doctest:: - >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc) - >>> for i in range(4): - ... u = u0 + i*HOUR - ... t = u.astimezone(Eastern) - ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold) - ... - 04:00:00 UTC = 00:00:00 EDT 0 - 05:00:00 UTC = 01:00:00 EDT 0 - 06:00:00 UTC = 01:00:00 EST 1 - 07:00:00 UTC = 02:00:00 EST 0 + >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc) + >>> for i in range(4): + ... u = u0 + i*HOUR + ... t = u.astimezone(Eastern) + ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold) + ... + 04:00:00 UTC = 00:00:00 EDT 0 + 05:00:00 UTC = 01:00:00 EDT 0 + 06:00:00 UTC = 01:00:00 EST 1 + 07:00:00 UTC = 02:00:00 EST 0 Note that the :class:`datetime` instances that differ only by the value of the :attr:`~datetime.fold` attribute are considered equal in comparisons. From b8ca45174b9bdf4d44b6ace3684cf9bae2beb12b Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 3 Mar 2017 09:41:30 +0100 Subject: [PATCH 4/4] bpo-27200: remove superfluous doctest directive --- Doc/library/datetime.rst | 48 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index c1ef1d2a78417e8..700a19d8e749249 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1806,20 +1806,18 @@ When DST starts (the "start" line), the local wall clock leaps from 1:59 to ``astimezone(Eastern)`` won't deliver a result with ``hour == 2`` on the day DST begins. For example, at the Spring forward transition of 2016, we get -.. doctest:: - - >>> from datetime import datetime, timezone - >>> from tzinfo_examples import HOUR, Eastern - >>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc) - >>> for i in range(4): - ... u = u0 + i*HOUR - ... t = u.astimezone(Eastern) - ... print(u.time(), 'UTC =', t.time(), t.tzname()) - ... - 05:00:00 UTC = 00:00:00 EST - 06:00:00 UTC = 01:00:00 EST - 07:00:00 UTC = 03:00:00 EDT - 08:00:00 UTC = 04:00:00 EDT + >>> from datetime import datetime, timezone + >>> from tzinfo_examples import HOUR, Eastern + >>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc) + >>> for i in range(4): + ... u = u0 + i*HOUR + ... t = u.astimezone(Eastern) + ... print(u.time(), 'UTC =', t.time(), t.tzname()) + ... + 05:00:00 UTC = 00:00:00 EST + 06:00:00 UTC = 01:00:00 EST + 07:00:00 UTC = 03:00:00 EDT + 08:00:00 UTC = 04:00:00 EDT When DST ends (the "end" line), there's a potentially worse problem: there's an @@ -1833,18 +1831,16 @@ form 5:MM and 6:MM both map to 1:MM when converted to Eastern, but earlier times have the :attr:`~datetime.fold` attribute set to 0 and the later times have it set to 1. For example, at the Fall back transition of 2016, we get -.. doctest:: - - >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc) - >>> for i in range(4): - ... u = u0 + i*HOUR - ... t = u.astimezone(Eastern) - ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold) - ... - 04:00:00 UTC = 00:00:00 EDT 0 - 05:00:00 UTC = 01:00:00 EDT 0 - 06:00:00 UTC = 01:00:00 EST 1 - 07:00:00 UTC = 02:00:00 EST 0 + >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc) + >>> for i in range(4): + ... u = u0 + i*HOUR + ... t = u.astimezone(Eastern) + ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold) + ... + 04:00:00 UTC = 00:00:00 EDT 0 + 05:00:00 UTC = 01:00:00 EDT 0 + 06:00:00 UTC = 01:00:00 EST 1 + 07:00:00 UTC = 02:00:00 EST 0 Note that the :class:`datetime` instances that differ only by the value of the :attr:`~datetime.fold` attribute are considered equal in comparisons.