[Python-checkins] bpo-34839: Add a 'before 3.6' in the section 'warnings' of doctest (GH-9736)
Miss Islington (bot)
webhook-mailer at python.org
Fri Apr 12 02:27:32 EDT 2019
https://github.com/python/cpython/commit/a910c2c6f3542b61f084de2ece0d8dab09c5a0fa
commit: a910c2c6f3542b61f084de2ece0d8dab09c5a0fa
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-04-11T23:27:27-07:00
summary:
bpo-34839: Add a 'before 3.6' in the section 'warnings' of doctest (GH-9736)
(cherry picked from commit 0522fd81dc6e3482c2d4c8719f1f85ad5924eede)
Co-authored-by: Stéphane Wirtel <stephane at wirtel.be>
files:
M Doc/library/doctest.rst
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index a138e6874a05..e7c0033eb6bc 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -771,23 +771,27 @@ Warnings
:mod:`doctest` is serious about requiring exact matches in expected output. If
even a single character doesn't match, the test fails. This will probably
surprise you a few times, as you learn exactly what Python does and doesn't
-guarantee about output. For example, when printing a dict, Python doesn't
-guarantee that the key-value pairs will be printed in any particular order, so a
-test like ::
+guarantee about output. For example, when printing a set, Python doesn't
+guarantee that the element is printed in any particular order, so a test like ::
>>> foo()
- {"Hermione": "hippogryph", "Harry": "broomstick"}
+ {"Hermione", "Harry"}
is vulnerable! One workaround is to do ::
- >>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
+ >>> foo() == {"Hermione", "Harry"}
True
instead. Another is to do ::
- >>> d = sorted(foo().items())
+ >>> d = sorted(foo())
>>> d
- [('Harry', 'broomstick'), ('Hermione', 'hippogryph')]
+ ['Harry', 'Hermione']
+
+.. note::
+
+ Before Python 3.6, when printing a dict, Python did not guarantee that
+ the key-value pairs was printed in any particular order.
There are others, but you get the idea.
More information about the Python-checkins
mailing list