]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-84623: Move imports in doctests (#94133)
authorVictor Stinner <vstinner@python.org>
Wed, 22 Jun 2022 20:24:45 +0000 (22:24 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Jun 2022 20:24:45 +0000 (22:24 +0200)
Move imports in doctests to prevent false alarms in pyflakes.

Lib/test/test_descrtut.py
Lib/test/test_doctest.py
Lib/test/test_extcall.py

index e01a31a74695d5ba3e09633824a8fd449c158e0e..b4158eb23a56f0c3c17ccc989e7fc797e7bc9c3b 100644 (file)
@@ -9,7 +9,6 @@
 # deterministic.
 
 from test.support import sortdict
-import pprint
 import doctest
 import unittest
 
@@ -167,6 +166,7 @@ For instance of built-in types, x.__class__ is now the same as type(x):
 
 You can get the information from the list type:
 
+    >>> import pprint
     >>> pprint.pprint(dir(list))    # like list.__dict__.keys(), but sorted
     ['__add__',
      '__class__',
index a4aab6cf4db3b5dae55951568683e8d744c0824b..7c799697d9c225fdc20e80886773a8a16ffa73d9 100644 (file)
@@ -4,7 +4,6 @@ Test script for doctest.
 
 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.abc
 import importlib.util
 import unittest
 import tempfile
-import shutil
 import types
 import contextlib
 
@@ -461,7 +459,7 @@ We'll simulate a __file__ attr that ends in pyc:
     >>> 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 @@ in it, and use a package hook to install a custom loader; on any platform,
 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)
index 13265ea0d8ce85063f097ac0e7dfc57867acd2cf..11d39ec63a49e329d18224d1995ecd36057f6128 100644 (file)
@@ -8,6 +8,7 @@ We're going the use these types for extra testing
 
 We're defining four helper functions
 
+    >>> from test import support
     >>> def e(a,b):
     ...     print(a, b)
 
@@ -522,7 +523,6 @@ Same with keyword only args:
 
 import doctest
 import unittest
-from test import support
 
 def load_tests(loader, tests, pattern):
     tests.addTest(doctest.DocTestSuite())