diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index 9a4ae592e7cd5568ac1a7b19645042becba4731c..69338552f13ecb80730127480f644b2e3d49a71d 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -167,7 +167,9 @@ class DownloadProgressMixin(object): def iter(self, it): # type: ignore for x in it: yield x - self.next(len(x)) + # B305 is incorrectly raised here + # https://github.com/PyCQA/flake8-bugbear/issues/59 + self.next(len(x)) # noqa: B305 self.finish() diff --git a/src/pip/_internal/commands/debug.py b/src/pip/_internal/commands/debug.py index d8e2484c1b4e9a518276e9ac92085086c1995805..ffe341dde7f7c10d2c156d258247e7afe79a40d0 100644 --- a/src/pip/_internal/commands/debug.py +++ b/src/pip/_internal/commands/debug.py @@ -87,7 +87,7 @@ def get_vendor_version_from_module(module_name): if not version: # Try to find version in debundled module info pkg_set = pkg_resources.WorkingSet( - [os.path.dirname(getattr(module, '__file__'))] + [os.path.dirname(getattr(module, '__file__', None))] ) package = pkg_set.find(pkg_resources.Requirement.parse(module_name)) version = getattr(package, 'version', None) @@ -166,7 +166,7 @@ def show_tags(options): def ca_bundle_info(config): # type: (Dict[str, str]) -> str levels = set() - for key, value in config.items(): + for key in config: levels.add(key.split('.')[0]) if not levels: diff --git a/src/pip/_internal/utils/filesystem.py b/src/pip/_internal/utils/filesystem.py index c706a038c2aabc943172715d29c670f7ec954560..303243fd22f201fb4b22a1d206ac703ef5214392 100644 --- a/src/pip/_internal/utils/filesystem.py +++ b/src/pip/_internal/utils/filesystem.py @@ -155,7 +155,7 @@ def _test_writable_dir_win(path): # and we can't use tempfile: http://bugs.python.org/issue22107 basename = 'accesstest_deleteme_fishfingers_custard_' alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789' - for i in range(10): + for _ in range(10): name = basename + ''.join(random.choice(alphabet) for _ in range(6)) file = os.path.join(path, name) try: @@ -190,7 +190,7 @@ def find_files(path, pattern): """Returns a list of absolute paths of files beneath path, recursively, with filenames which match the UNIX-style shell glob pattern.""" result = [] # type: List[str] - for root, dirs, files in os.walk(path): + for root, _, files in os.walk(path): matches = fnmatch.filter(files, pattern) result.extend(os.path.join(root, f) for f in matches) return result diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index c7bb972ffb7d39643c76a9db3007255a28e4da36..467ae5452e174053e9275fde65f447ec390dcb3f 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -17,7 +17,7 @@ import stat import sys from collections import deque -from pip._vendor import pkg_resources +from pip._vendor import pkg_resources, six # NOTE: retrying is not annotated in typeshed as on 2017-07-17, which is # why we ignore the type on this import. from pip._vendor.retrying import retry # type: ignore @@ -548,7 +548,10 @@ class FakeFile(object): try: return next(self._gen) except NameError: - return self._gen.next() + # flake8-bugbear B305 suggests using six.next for + # Python 2 compatibility. This along with the try/except + # block can be removed once we drop Python 2 support + return six.next(self._gen) except StopIteration: return '' diff --git a/src/pip/_internal/vcs/subversion.py b/src/pip/_internal/vcs/subversion.py index 4324a5d9f8270f7f92cfc080969082538d6de8ab..14825f791a458581975b01158cfe44d93ff6cb33 100644 --- a/src/pip/_internal/vcs/subversion.py +++ b/src/pip/_internal/vcs/subversion.py @@ -56,7 +56,7 @@ class Subversion(VersionControl): # Note: taken from setuptools.command.egg_info revision = 0 - for base, dirs, files in os.walk(location): + for base, dirs, _ in os.walk(location): if cls.dirname not in dirs: dirs[:] = [] continue # no sense walking uncontrolled subdirs diff --git a/src/pip/_internal/wheel_builder.py b/src/pip/_internal/wheel_builder.py index b5e8bf339249445e0a5287374566408670e2b62c..8b6ddad47399deef5366d07cc976020abe299f59 100644 --- a/src/pip/_internal/wheel_builder.py +++ b/src/pip/_internal/wheel_builder.py @@ -23,7 +23,7 @@ from pip._internal.vcs import vcs if MYPY_CHECK_RUNNING: from typing import ( - Any, Callable, Iterable, List, Optional, Pattern, Tuple, + Any, Callable, Iterable, List, Optional, Tuple, ) from pip._internal.cache import WheelCache @@ -34,11 +34,11 @@ if MYPY_CHECK_RUNNING: logger = logging.getLogger(__name__) +_egg_info_re = re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', re.IGNORECASE) -def _contains_egg_info( - s, _egg_info_re=re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', - re.IGNORECASE)): - # type: (str, Pattern[str]) -> bool + +def _contains_egg_info(s): + # type: (str) -> bool """Determine whether the string looks like an egg_info. :param s: The string to parse. E.g. foo-2.1