[Python-checkins] gh-84623: Remove unused imports (#94132)

vstinner webhook-mailer at python.org
Wed Jun 22 13:14:36 EDT 2022


https://github.com/python/cpython/commit/47e35625ff2c4e6511a12e7178c3e4fbc965b634
commit: 47e35625ff2c4e6511a12e7178c3e4fbc965b634
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-06-22T19:14:27+02:00
summary:

gh-84623: Remove unused imports (#94132)

files:
M Doc/includes/email-headers.py
M Doc/tools/extensions/asdl_highlight.py
M Doc/tools/extensions/peg_highlight.py
M Doc/tools/extensions/pyspecific.py
M Lib/random.py
M Lib/test/test_asyncio/test_unix_events.py
M Lib/test/test_ctypes/test_parameters.py
M Lib/test/test_sqlite3/test_transactions.py
M Lib/test/test_unittest/test_program.py
M Lib/test/test_unittest/test_result.py
M Lib/tkinter/test/support.py
M Lib/tkinter/test/widget_tests.py
M PC/layout/main.py
M PC/layout/support/appxmanifest.py
M PC/layout/support/catalog.py
M PC/layout/support/constants.py
M Parser/asdl_c.py
M Tools/clinic/clinic.py
M Tools/peg_generator/pegen/grammar.py
M Tools/peg_generator/scripts/grammar_grapher.py
M Tools/peg_generator/scripts/test_parse_directory.py
M Tools/peg_generator/scripts/test_pypi_packages.py
M Tools/scripts/freeze_modules.py
M Tools/scripts/generate_re_casefix.py
M Tools/scripts/pathfix.py
M Tools/scripts/stable_abi.py
M Tools/scripts/summarize_stats.py
M Tools/ssl/multissltests.py

diff --git a/Doc/includes/email-headers.py b/Doc/includes/email-headers.py
index 2c421451a8e5a..5def0c90d28d9 100644
--- a/Doc/includes/email-headers.py
+++ b/Doc/includes/email-headers.py
@@ -1,5 +1,6 @@
 # Import the email modules we'll need
-from email.parser import BytesParser, Parser
+#from email.parser import BytesParser
+from email.parser import Parser
 from email.policy import default
 
 # If the e-mail headers are in a file, uncomment these two lines:
diff --git a/Doc/tools/extensions/asdl_highlight.py b/Doc/tools/extensions/asdl_highlight.py
index b1989e5395707..42863a4b3bcd6 100644
--- a/Doc/tools/extensions/asdl_highlight.py
+++ b/Doc/tools/extensions/asdl_highlight.py
@@ -1,4 +1,3 @@
-import os
 import sys
 from pathlib import Path
 
@@ -6,7 +5,7 @@
 sys.path.append(str(CPYTHON_ROOT / "Parser"))
 
 from pygments.lexer import RegexLexer, bygroups, include, words
-from pygments.token import (Comment, Generic, Keyword, Name, Operator,
+from pygments.token import (Comment, Keyword, Name, Operator,
                             Punctuation, Text)
 
 from asdl import builtin_types
diff --git a/Doc/tools/extensions/peg_highlight.py b/Doc/tools/extensions/peg_highlight.py
index 27f54cdf593c8..4bdc2ee186133 100644
--- a/Doc/tools/extensions/peg_highlight.py
+++ b/Doc/tools/extensions/peg_highlight.py
@@ -1,5 +1,5 @@
 from pygments.lexer import RegexLexer, bygroups, include
-from pygments.token import Comment, Generic, Keyword, Name, Operator, Punctuation, Text
+from pygments.token import Comment, Keyword, Name, Operator, Punctuation, Text
 
 from sphinx.highlighting import lexers
 
diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py
index 68c1e1b7bbd79..8ac0028cc4f41 100644
--- a/Doc/tools/extensions/pyspecific.py
+++ b/Doc/tools/extensions/pyspecific.py
@@ -30,7 +30,6 @@
 from sphinx.util import status_iterator, logging
 from sphinx.util.nodes import split_explicit_title
 from sphinx.writers.text import TextWriter, TextTranslator
-from sphinx.writers.latex import LaTeXTranslator
 
 try:
     from sphinx.domains.python import PyFunction, PyMethod
diff --git a/Lib/random.py b/Lib/random.py
index a2dfcb574bd5e..2166474af0554 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -50,7 +50,7 @@
 from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
 from math import tau as TWOPI, floor as _floor, isfinite as _isfinite
 from os import urandom as _urandom
-from _collections_abc import Set as _Set, Sequence as _Sequence
+from _collections_abc import Sequence as _Sequence
 from operator import index as _index
 from itertools import accumulate as _accumulate, repeat as _repeat
 from bisect import bisect as _bisect
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 23d2e8ad40164..9918165909f7f 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -9,7 +9,6 @@
 import socket
 import stat
 import sys
-import tempfile
 import threading
 import unittest
 from unittest import mock
diff --git a/Lib/test/test_ctypes/test_parameters.py b/Lib/test/test_ctypes/test_parameters.py
index 2f755a6d09f90..84839d9c6a96d 100644
--- a/Lib/test/test_ctypes/test_parameters.py
+++ b/Lib/test/test_ctypes/test_parameters.py
@@ -5,7 +5,6 @@
 class SimpleTypesTestCase(unittest.TestCase):
 
     def setUp(self):
-        import ctypes
         try:
             from _ctypes import set_conversion_mode
         except ImportError:
diff --git a/Lib/test/test_sqlite3/test_transactions.py b/Lib/test/test_sqlite3/test_transactions.py
index a67d72709d39a..9c3d19e79bd98 100644
--- a/Lib/test/test_sqlite3/test_transactions.py
+++ b/Lib/test/test_sqlite3/test_transactions.py
@@ -20,7 +20,7 @@
 #    misrepresented as being the original software.
 # 3. This notice may not be removed or altered from any source distribution.
 
-import os, unittest
+import unittest
 import sqlite3 as sqlite
 
 from test.support import LOOPBACK_TIMEOUT
diff --git a/Lib/test/test_unittest/test_program.py b/Lib/test/test_unittest/test_program.py
index 169fc4ed9401f..3fecbcda95fa3 100644
--- a/Lib/test/test_unittest/test_program.py
+++ b/Lib/test/test_unittest/test_program.py
@@ -1,5 +1,3 @@
-import io
-
 import os
 import sys
 import subprocess
diff --git a/Lib/test/test_unittest/test_result.py b/Lib/test/test_unittest/test_result.py
index b0cc3d867d6e5..eeb15992fd109 100644
--- a/Lib/test/test_unittest/test_result.py
+++ b/Lib/test/test_unittest/test_result.py
@@ -2,7 +2,7 @@
 import sys
 import textwrap
 
-from test.support import warnings_helper, captured_stdout, captured_stderr
+from test.support import warnings_helper, captured_stdout
 
 import traceback
 import unittest
diff --git a/Lib/tkinter/test/support.py b/Lib/tkinter/test/support.py
index 9e26d04536f22..9154ebac5c48f 100644
--- a/Lib/tkinter/test/support.py
+++ b/Lib/tkinter/test/support.py
@@ -1,5 +1,4 @@
 import functools
-import re
 import tkinter
 import unittest
 
diff --git a/Lib/tkinter/test/widget_tests.py b/Lib/tkinter/test/widget_tests.py
index a450544c3ee6b..8418154d64a85 100644
--- a/Lib/tkinter/test/widget_tests.py
+++ b/Lib/tkinter/test/widget_tests.py
@@ -1,6 +1,5 @@
 # Common tests for test_tkinter/test_widgets.py and test_ttk/test_widgets.py
 
-import unittest
 import tkinter
 from tkinter.test.support import (AbstractTkTest, tcl_version,
                                   pixels_conv, tcl_obj_eq)
diff --git a/PC/layout/main.py b/PC/layout/main.py
index 8e69ecc259121..923483ad4a3f7 100644
--- a/PC/layout/main.py
+++ b/PC/layout/main.py
@@ -8,11 +8,8 @@
 __version__ = "3.8"
 
 import argparse
-import functools
 import os
-import re
 import shutil
-import subprocess
 import sys
 import tempfile
 import zipfile
diff --git a/PC/layout/support/appxmanifest.py b/PC/layout/support/appxmanifest.py
index 427a36f31c8f9..4850fad9b56d8 100644
--- a/PC/layout/support/appxmanifest.py
+++ b/PC/layout/support/appxmanifest.py
@@ -6,13 +6,11 @@
 __version__ = "3.8"
 
 
-import collections
 import ctypes
 import io
 import os
-import sys
 
-from pathlib import Path, PureWindowsPath
+from pathlib import PureWindowsPath
 from xml.etree import ElementTree as ET
 
 from .constants import *
diff --git a/PC/layout/support/catalog.py b/PC/layout/support/catalog.py
index 43121187ed180..c9d87cb89484c 100644
--- a/PC/layout/support/catalog.py
+++ b/PC/layout/support/catalog.py
@@ -6,8 +6,6 @@
 __version__ = "3.8"
 
 
-import sys
-
 __all__ = ["PYTHON_CAT_NAME", "PYTHON_CDF_NAME"]
 
 
diff --git a/PC/layout/support/constants.py b/PC/layout/support/constants.py
index 6efd8bcd5cbb5..8195c3dc30cdc 100644
--- a/PC/layout/support/constants.py
+++ b/PC/layout/support/constants.py
@@ -6,7 +6,6 @@
 __version__ = "3.8"
 
 import os
-import re
 import struct
 import sys
 
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 1101a3593dfe2..bf391a3ae1653 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -1,7 +1,6 @@
 #! /usr/bin/env python
 """Generate C code from an ASDL description."""
 
-import os
 import sys
 import textwrap
 import types
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 53e29df8a8e40..f0f2d205c419d 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -22,7 +22,6 @@
 import shlex
 import string
 import sys
-import tempfile
 import textwrap
 import traceback
 import types
diff --git a/Tools/peg_generator/pegen/grammar.py b/Tools/peg_generator/pegen/grammar.py
index fa47b98201c0f..03d60d01026f8 100644
--- a/Tools/peg_generator/pegen/grammar.py
+++ b/Tools/peg_generator/pegen/grammar.py
@@ -1,23 +1,16 @@
 from __future__ import annotations
 
-from abc import abstractmethod
 from typing import (
-    TYPE_CHECKING,
     AbstractSet,
     Any,
-    Dict,
     Iterable,
     Iterator,
     List,
     Optional,
-    Set,
     Tuple,
     Union,
 )
 
-if TYPE_CHECKING:
-    from pegen.parser_generator import ParserGenerator
-
 
 class GrammarError(Exception):
     pass
diff --git a/Tools/peg_generator/scripts/grammar_grapher.py b/Tools/peg_generator/scripts/grammar_grapher.py
index 4a41dfaa3da0f..e5271a0e4810f 100755
--- a/Tools/peg_generator/scripts/grammar_grapher.py
+++ b/Tools/peg_generator/scripts/grammar_grapher.py
@@ -30,7 +30,6 @@
     Alt,
     Cut,
     Forced,
-    Grammar,
     Group,
     Leaf,
     Lookahead,
diff --git a/Tools/peg_generator/scripts/test_parse_directory.py b/Tools/peg_generator/scripts/test_parse_directory.py
index a5e26f0a0feda..f5cf198be8dab 100755
--- a/Tools/peg_generator/scripts/test_parse_directory.py
+++ b/Tools/peg_generator/scripts/test_parse_directory.py
@@ -5,7 +5,6 @@
 import os
 import sys
 import time
-import traceback
 import tokenize
 from glob import glob, escape
 from pathlib import PurePath
@@ -13,7 +12,6 @@
 from typing import List, Optional, Any, Tuple
 
 sys.path.insert(0, os.getcwd())
-from pegen.ast_dump import ast_dump
 from pegen.testutil import print_memstats
 
 SUCCESS = "\033[92m"
diff --git a/Tools/peg_generator/scripts/test_pypi_packages.py b/Tools/peg_generator/scripts/test_pypi_packages.py
index e2eaef9de26f7..01ccc3d21ef5a 100755
--- a/Tools/peg_generator/scripts/test_pypi_packages.py
+++ b/Tools/peg_generator/scripts/test_pypi_packages.py
@@ -9,11 +9,10 @@
 import pathlib
 import sys
 
-from typing import Generator, Any
+from typing import Generator
 
 sys.path.insert(0, ".")
 
-from pegen import build
 from scripts import test_parse_directory
 
 HERE = pathlib.Path(__file__).resolve().parent
diff --git a/Tools/scripts/freeze_modules.py b/Tools/scripts/freeze_modules.py
index dd208c7847194..aa1e4fe2ea0f4 100644
--- a/Tools/scripts/freeze_modules.py
+++ b/Tools/scripts/freeze_modules.py
@@ -8,7 +8,6 @@
 import os
 import ntpath
 import posixpath
-import sys
 import argparse
 from update_file import updating_file_with_tmpfile
 
diff --git a/Tools/scripts/generate_re_casefix.py b/Tools/scripts/generate_re_casefix.py
index 00b048b5d716c..625b0658d97d1 100755
--- a/Tools/scripts/generate_re_casefix.py
+++ b/Tools/scripts/generate_re_casefix.py
@@ -2,7 +2,6 @@
 # This script generates Lib/re/_casefix.py.
 
 import collections
-import re
 import sys
 import unicodedata
 
diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py
index d252321a21a17..f957b11547179 100755
--- a/Tools/scripts/pathfix.py
+++ b/Tools/scripts/pathfix.py
@@ -27,7 +27,6 @@
 # into a program for a different change to Python programs...
 
 import sys
-import re
 import os
 from stat import *
 import getopt
diff --git a/Tools/scripts/stable_abi.py b/Tools/scripts/stable_abi.py
index f5a9f8d2dd617..d557e102ea8e6 100755
--- a/Tools/scripts/stable_abi.py
+++ b/Tools/scripts/stable_abi.py
@@ -16,7 +16,6 @@
 import textwrap
 import tomllib
 import difflib
-import shutil
 import pprint
 import sys
 import os
diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py
index 93a9b6baea329..26e9c4ecb1679 100644
--- a/Tools/scripts/summarize_stats.py
+++ b/Tools/scripts/summarize_stats.py
@@ -7,7 +7,6 @@
 import opcode
 from datetime import date
 import itertools
-import argparse
 import sys
 
 if os.name == "nt":
diff --git a/Tools/ssl/multissltests.py b/Tools/ssl/multissltests.py
index 82076808bfd37..fc6b2d0f8becf 100755
--- a/Tools/ssl/multissltests.py
+++ b/Tools/ssl/multissltests.py
@@ -35,7 +35,6 @@
     from urllib2 import urlopen, HTTPError
 import re
 import shutil
-import string
 import subprocess
 import sys
 import tarfile



More information about the Python-checkins mailing list