[Python-checkins] gh-84623: Move imports in doctests (#94133)

vstinner webhook-mailer at python.org
Wed Jun 22 16:24:51 EDT 2022


https://github.com/python/cpython/commit/e52009d3f623c683aa22b4732fdf7fc2e55ede7c
commit: e52009d3f623c683aa22b4732fdf7fc2e55ede7c
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-06-22T22:24:45+02:00
summary:

gh-84623: Move imports in doctests (#94133)

Move imports in doctests to prevent false alarms in pyflakes.

files:
M Lib/test/test_descrtut.py
M Lib/test/test_doctest.py
M Lib/test/test_extcall.py

diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py
index e01a31a74695d..b4158eb23a56f 100644
--- a/Lib/test/test_descrtut.py
+++ b/Lib/test/test_descrtut.py
@@ -9,7 +9,6 @@
 # deterministic.
 
 from test.support import sortdict
-import pprint
 import doctest
 import unittest
 
@@ -167,6 +166,7 @@ def merge(self, other):
 
 You can get the information from the list type:
 
+    >>> import pprint
     >>> pprint.pprint(dir(list))    # like list.__dict__.keys(), but sorted
     ['__add__',
      '__class__',
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index a4aab6cf4db3b..7c799697d9c22 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -4,7 +4,6 @@
 
 from test import support
 from test.support import import_helper
-from test.support import os_helper
 import doctest
 import functools
 import os
@@ -14,7 +13,6 @@
 import importlib.util
 import unittest
 import tempfile
-import shutil
 import types
 import contextlib
 
@@ -461,7 +459,7 @@ def basics(): r"""
     >>> tests = finder.find(sample_func)
 
     >>> print(tests)  # doctest: +ELLIPSIS
-    [<DocTest sample_func from test_doctest.py:34 (1 example)>]
+    [<DocTest sample_func from test_doctest.py:32 (1 example)>]
 
 The exact name depends on how test_doctest was invoked, so allow for
 leading path components.
@@ -2811,6 +2809,8 @@ def test_lineendings(): r"""
 at least one of the line endings will raise a ValueError for inconsistent
 whitespace if doctest does not correctly do the newline conversion.
 
+    >>> from test.support import os_helper
+    >>> import shutil
     >>> dn = tempfile.mkdtemp()
     >>> pkg = os.path.join(dn, "doctest_testpkg")
     >>> os.mkdir(pkg)
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 13265ea0d8ce8..11d39ec63a49e 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -8,6 +8,7 @@
 
 We're defining four helper functions
 
+    >>> from test import support
     >>> def e(a,b):
     ...     print(a, b)
 
@@ -522,7 +523,6 @@
 
 import doctest
 import unittest
-from test import support
 
 def load_tests(loader, tests, pattern):
     tests.addTest(doctest.DocTestSuite())



More information about the Python-checkins mailing list