Skip to content

Commit 07bf33f

Browse files
committed
MAINT: cleanup unused imports; avoid redefinition of imports
* Cleanup unused imports (F401) of mostly standard Python modules, or some internal but unlikely referenced modules * Where internal imports are potentially used, mark with noqa * Avoid redefinition of imports (F811)
1 parent a9bc5db commit 07bf33f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+27
-82
lines changed

benchmarks/benchmarks/bench_random.py

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import numpy as np
44

5-
from numpy.random import RandomState
6-
75
try:
86
from numpy.random import Generator
97
except ImportError:

benchmarks/benchmarks/bench_records.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
from .common import Benchmark
42

53
import numpy as np

doc/neps/tools/build_index.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import os
7-
import sys
87
import jinja2
98
import glob
109
import re

doc/postprocess.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
MODE is either 'html' or 'tex'.
77
88
"""
9-
import re
109
import optparse
1110
import io
1211

doc/source/conf.py

-2
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ def setup(app):
257257
# Autosummary
258258
# -----------------------------------------------------------------------------
259259

260-
import glob
261260
autosummary_generate = True
262261

263262
# -----------------------------------------------------------------------------
@@ -381,7 +380,6 @@ def linkcode_resolve(domain, info):
381380
numpy.__version__, fn, linespec)
382381

383382
from pygments.lexers import CLexer
384-
from pygments import token
385383
import copy
386384

387385
class NumPyLexer(CLexer):

doc/source/user/plots/matplotlib3.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
3-
from matplotlib import cm
43
from mpl_toolkits.mplot3d import Axes3D
54

65
fig = plt.figure()

numpy/core/_type_aliases.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
2424
"""
2525
import warnings
26-
import sys
2726

2827
from numpy.compat import unicode
2928
from numpy._globals import VisibleDeprecationWarning

numpy/core/code_generators/generate_ufunc_api.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import numpy_api
55

6-
from genapi import \
7-
TypeApi, GlobalVarApi, FunctionApi, BoolValuesApi
6+
from genapi import TypeApi, FunctionApi
87

98
h_template = r"""
109
#ifdef _UMATHMODULE

numpy/core/function_base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import types
55

66
from . import numeric as _nx
7-
from .numeric import (result_type, NaN, shares_memory, MAY_SHARE_BOUNDS,
8-
TooHardError, asanyarray, ndim)
7+
from .numeric import result_type, NaN, asanyarray, ndim
98
from numpy.core.multiarray import add_docstring
109
from numpy.core import overrides
1110

numpy/core/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def visibility_define(config):
392392

393393
def configuration(parent_package='',top_path=None):
394394
from numpy.distutils.misc_util import Configuration, dot_join
395-
from numpy.distutils.system_info import get_info, dict_append
395+
from numpy.distutils.system_info import get_info
396396

397397
config = Configuration('core', parent_package, top_path)
398398
local_dir = config.local_path

numpy/core/umath.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
from . import _multiarray_umath
1010
from ._multiarray_umath import * # noqa: F403
11-
from ._multiarray_umath import (
12-
_UFUNC_API, _add_newdoc_ufunc, _ones_like
13-
)
11+
from ._multiarray_umath import _UFUNC_API, _add_newdoc_ufunc
1412

1513
__all__ = [
1614
'_UFUNC_API', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_IGNORE', 'ERR_LOG',

numpy/distutils/command/build_clib.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
from numpy.distutils import log
1111
from distutils.dep_util import newer_group
12-
from numpy.distutils.misc_util import filter_sources, has_f_sources,\
13-
has_cxx_sources, all_strings, get_lib_source_files, is_sequence, \
14-
get_numpy_include_dirs
12+
from numpy.distutils.misc_util import (
13+
filter_sources, get_lib_source_files, get_numpy_include_dirs,
14+
has_cxx_sources, has_f_sources, is_sequence
15+
)
1516

1617
# Fix Python distutils bug sf #1718574:
1718
_l = old_build_clib.user_options

numpy/distutils/command/build_ext.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
from numpy.distutils import log
1515
from numpy.distutils.exec_command import filepath_from_subprocess_output
16-
from numpy.distutils.system_info import combine_paths, system_info
17-
from numpy.distutils.misc_util import filter_sources, has_f_sources, \
18-
has_cxx_sources, get_ext_source_files, \
19-
get_numpy_include_dirs, is_sequence, get_build_architecture, \
20-
msvc_version
16+
from numpy.distutils.system_info import combine_paths
17+
from numpy.distutils.misc_util import (
18+
filter_sources, get_ext_source_files, get_numpy_include_dirs,
19+
has_cxx_sources, has_f_sources, is_sequence
20+
)
2121
from numpy.distutils.command.config_compiler import show_fortran_compilers
2222

2323

numpy/distutils/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from distutils.core import Distribution, setup
2+
from distutils.core import Distribution
33

44
if 'setuptools' in sys.modules:
55
have_setuptools = True
@@ -25,7 +25,7 @@
2525
build, build_py, build_ext, build_clib, build_src, build_scripts, \
2626
sdist, install_data, install_headers, install, bdist_rpm, \
2727
install_clib
28-
from numpy.distutils.misc_util import get_data_files, is_sequence, is_string
28+
from numpy.distutils.misc_util import is_sequence, is_string
2929

3030
numpy_cmdclass = {'build': build.build,
3131
'build_src': build_src.build_src,

numpy/distutils/extension.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
Overridden to support f2py.
77
88
"""
9-
import sys
109
import re
1110
from distutils.extension import Extension as old_Extension
1211

numpy/distutils/fcompiler/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import os
2020
import sys
2121
import re
22-
import types
2322

2423
from numpy.compat import open_latin1
2524

numpy/distutils/fcompiler/environment.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import warnings
32
from distutils.dist import Distribution
43

54
__metaclass__ = type

numpy/distutils/fcompiler/gnu.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from subprocess import Popen, PIPE, STDOUT
1111
from numpy.distutils.exec_command import filepath_from_subprocess_output
1212
from numpy.distutils.fcompiler import FCompiler
13-
from numpy.distutils.system_info import system_info
1413

1514
compilers = ['GnuFCompiler', 'Gnu95FCompiler']
1615

numpy/distutils/fcompiler/pg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# http://www.pgroup.com
22
import sys
33

4-
from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
4+
from numpy.distutils.fcompiler import FCompiler
55
from sys import platform
66
from os.path import join, dirname, normpath
77

numpy/distutils/mingw32ccompiler.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import textwrap
1515

1616
# Overwrite certain distutils.ccompiler functions:
17-
import numpy.distutils.ccompiler
17+
import numpy.distutils.ccompiler # noqa: F401
1818
from numpy.distutils import log
1919
# NT stuff
2020
# 1. Make sure libpython<version>.a exists for gcc. If not, build it.
@@ -26,8 +26,7 @@
2626
from distutils.version import StrictVersion
2727
from distutils.unixccompiler import UnixCCompiler
2828
from distutils.msvccompiler import get_build_version as get_build_msvc_version
29-
from distutils.errors import (DistutilsExecError, CompileError,
30-
UnknownFileError)
29+
from distutils.errors import UnknownFileError
3130
from numpy.distutils.misc_util import (msvc_runtime_library,
3231
msvc_runtime_version,
3332
msvc_runtime_major,

numpy/distutils/npy_pkg_config.py

-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ def read_config(pkgname, dirs=None):
375375
# pkg-config simple emulator - useful for debugging, and maybe later to query
376376
# the system
377377
if __name__ == '__main__':
378-
import sys
379378
from optparse import OptionParser
380379
import glob
381380

numpy/distutils/system_info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177

178178
from numpy.distutils.exec_command import (
179179
find_executable, filepath_from_subprocess_output,
180-
get_pythonexe)
180+
)
181181
from numpy.distutils.misc_util import (is_sequence, is_string,
182182
get_shared_lib_extension)
183183
from numpy.distutils.command.config import config as cmd_config

numpy/distutils/tests/test_fcompiler.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import pytest
2-
3-
from numpy.testing import assert_, suppress_warnings
1+
from numpy.testing import assert_
42
import numpy.distutils.fcompiler
53

64
customizable_flags = [

numpy/distutils/tests/test_shell_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
import subprocess
3-
import os
43
import json
54
import sys
65

numpy/f2py/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import subprocess
99
import os
1010

11-
import numpy as np
12-
1311
from . import f2py2e
1412
from . import f2py_testing
1513
from . import diagnose

numpy/f2py/capi_maps.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import copy
2020
import re
2121
import os
22-
import sys
2322
from .crackfortran import markoutercomma
2423
from . import cb_rules
2524

numpy/f2py/tests/test_crackfortran.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import pytest
2-
31
import numpy as np
42
from numpy.testing import assert_array_equal
53
from . import util

numpy/f2py/tests/test_quoted_character.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
"""
44
import sys
5-
from importlib import import_module
65
import pytest
76

87
from numpy.testing import assert_equal

numpy/fft/tests/test_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
"""
66
import numpy as np
7-
from numpy.testing import assert_array_almost_equal, assert_equal
7+
from numpy.testing import assert_array_almost_equal
88
from numpy import fft, pi
99

1010

numpy/fft/tests/test_pocketfft.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
assert_array_equal, assert_raises, assert_allclose
66
)
77
import threading
8-
import sys
98
import queue
109

1110

numpy/lib/_datasource.py

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
3636
"""
3737
import os
38-
import sys
3938
import shutil
4039
import io
4140
from contextlib import closing

numpy/ma/mrecords.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# first place, and then rename the invalid fields with a trailing
1414
# underscore. Maybe we could just overload the parser function ?
1515

16-
import sys
1716
import warnings
1817

1918
import numpy as np

numpy/random/tests/test_extending.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def test_cython(tmp_path):
5050
@pytest.mark.skipif(numba is None or cffi is None,
5151
reason="requires numba and cffi")
5252
def test_numba():
53-
from numpy.random._examples.numba import extending
53+
from numpy.random._examples.numba import extending # noqa: F401
5454

5555
@pytest.mark.skipif(cffi is None, reason="requires cffi")
5656
def test_cffi():
57-
from numpy.random._examples.cffi import extending
57+
from numpy.random._examples.cffi import extending # noqa: F401

numpy/testing/_private/parameterized.py

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
3232
"""
3333
import re
34-
import sys
3534
import inspect
3635
import warnings
3736
from functools import wraps

numpy/testing/tests/test_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33
import os
44
import itertools
5-
import textwrap
65
import pytest
76
import weakref
87

numpy/tests/test_reloading.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
from numpy.testing import assert_raises, assert_, assert_equal
42
from numpy.compat import pickle
53

numpy/tests/test_scripts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import subprocess
1010

1111
import numpy as np
12-
from numpy.testing import assert_, assert_equal
12+
from numpy.testing import assert_equal
1313

1414
is_inplace = isfile(pathjoin(dirname(np.__file__), '..', 'setup.py'))
1515

numpy/tests/test_warnings.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Tests which scan for certain occurrences in the code, they may not find
33
all of these occurrences but should catch almost all.
44
"""
5-
import sys
65
import pytest
76

87
from pathlib import Path

pavement.py

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import os
2626
import sys
2727
import shutil
28-
import subprocess
29-
import re
3028
import hashlib
3129

3230
# The paver package needs to be installed to run tasks

runtests.py

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
import sys
5555
import os
56-
import builtins
5756

5857
# In case we are run from the source directory, we don't want to import the
5958
# project from there:

setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,9 @@ def setup_package():
458458
# Raise errors for unsupported commands, improve help output, etc.
459459
run_build = parse_setuppy_commands()
460460

461-
from setuptools import setup
462461
if run_build:
462+
# patches distutils, even though we don't use it
463+
import setuptools # noqa: F401
463464
from numpy.distutils.core import setup
464465
cwd = os.path.abspath(os.path.dirname(__file__))
465466
if not 'sdist' in sys.argv:
@@ -470,6 +471,7 @@ def setup_package():
470471
# Customize extension building
471472
cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides()
472473
else:
474+
from setuptools import setup
473475
# Version number is added to metadata inside configuration() if build
474476
# is run.
475477
metadata['version'] = get_version_info()[0]

tools/openblas_support.py

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def setup_openblas(arch=get_arch(), ilp64=get_ilp64()):
103103
return unpack_targz(tmp)
104104

105105
def unpack_windows_zip(fname):
106-
import sysconfig
107106
with zipfile.ZipFile(fname, 'r') as zf:
108107
# Get the openblas.a file, but not openblas.dll.a nor openblas.dev.a
109108
lib = [x for x in zf.namelist() if OPENBLAS_LONG in x and

0 commit comments

Comments
 (0)