summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2012-06-16 00:19:47 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2012-06-16 00:19:47 (GMT)
commit0831382d69890eeab58f43588887058a52a1f4b5 (patch)
treef749634dbfbc248dec21b74d676f28c3b23a605e /Doc
parentea0b8239401123fa7f41c74f6fc9ded1cf74088a (diff)
downloadcpython-0831382d69890eeab58f43588887058a52a1f4b5.zip
cpython-0831382d69890eeab58f43588887058a52a1f4b5.tar.gz
cpython-0831382d69890eeab58f43588887058a52a1f4b5.tar.bz2
Issue #15006: Allow equality comparison between naive and aware time
or datetime objects.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/datetime.rst20
1 files changed, 18 insertions, 2 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 72e35df..5c2d3d9 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -901,13 +901,21 @@ Supported operations:
*datetime1* is considered less than *datetime2* when *datetime1* precedes
*datetime2* in time.
- If one comparand is naive and the other is aware, :exc:`TypeError` is raised.
+ If one comparand is naive and the other is aware, :exc:`TypeError`
+ is raised if an order comparison is attempted. For equality
+ comparisons, naive instances are never equal to aware instances.
+
If both comparands are aware, and have the same :attr:`tzinfo` attribute, the
common :attr:`tzinfo` attribute is ignored and the base datetimes are
compared. If both comparands are aware and have different :attr:`tzinfo`
attributes, the comparands are first adjusted by subtracting their UTC
offsets (obtained from ``self.utcoffset()``).
+ .. versionchanged:: 3.3
+
+ Equality comparisons between naive and aware :class:`datetime`
+ instances don't raise :exc:`TypeError`.
+
.. note::
In order to stop comparison from falling back to the default scheme of comparing
@@ -1316,7 +1324,10 @@ Supported operations:
* comparison of :class:`.time` to :class:`.time`, where *a* is considered less
than *b* when *a* precedes *b* in time. If one comparand is naive and the other
- is aware, :exc:`TypeError` is raised. If both comparands are aware, and have
+ is aware, :exc:`TypeError` is raised if an order comparison is attempted. For equality
+ comparisons, naive instances are never equal to aware instances.
+
+ If both comparands are aware, and have
the same :attr:`tzinfo` attribute, the common :attr:`tzinfo` attribute is
ignored and the base times are compared. If both comparands are aware and
have different :attr:`tzinfo` attributes, the comparands are first adjusted by
@@ -1326,6 +1337,11 @@ Supported operations:
different type, :exc:`TypeError` is raised unless the comparison is ``==`` or
``!=``. The latter cases return :const:`False` or :const:`True`, respectively.
+ .. versionchanged:: 3.3
+
+ Equality comparisons between naive and aware :class:`time` instances
+ don't raise :exc:`TypeError`.
+
* hash, use as dict key
* efficient pickling