Skip to content

Commit 0522fd8

Browse files
matrixiseJulienPalard
authored andcommitted
bpo-34839: Add a 'before 3.6' in the section 'warnings' of doctest (GH-9736)
1 parent a5259fb commit 0522fd8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Doc/library/doctest.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -759,23 +759,27 @@ Warnings
759759
:mod:`doctest` is serious about requiring exact matches in expected output. If
760760
even a single character doesn't match, the test fails. This will probably
761761
surprise you a few times, as you learn exactly what Python does and doesn't
762-
guarantee about output. For example, when printing a dict, Python doesn't
763-
guarantee that the key-value pairs will be printed in any particular order, so a
764-
test like ::
762+
guarantee about output. For example, when printing a set, Python doesn't
763+
guarantee that the element is printed in any particular order, so a test like ::
765764

766765
>>> foo()
767-
{"Hermione": "hippogryph", "Harry": "broomstick"}
766+
{"Hermione", "Harry"}
768767

769768
is vulnerable! One workaround is to do ::
770769

771-
>>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
770+
>>> foo() == {"Hermione", "Harry"}
772771
True
773772

774773
instead. Another is to do ::
775774

776-
>>> d = sorted(foo().items())
775+
>>> d = sorted(foo())
777776
>>> d
778-
[('Harry', 'broomstick'), ('Hermione', 'hippogryph')]
777+
['Harry', 'Hermione']
778+
779+
.. note::
780+
781+
Before Python 3.6, when printing a dict, Python did not guarantee that
782+
the key-value pairs was printed in any particular order.
779783

780784
There are others, but you get the idea.
781785

0 commit comments

Comments
 (0)