Skip to content

Fix "src/pip" to respect flake8-bugbear #8405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
9 changes: 7 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ exclude =
per-file-ignores =
# B011: Do not call assert False since python -O removes these calls
tests/*: B011
# TODO: Remove this when fixing flake8-bugbear warnings in source
src/pip/*: B007,B008,B009,B014,B305
# TODO: Remove IOError from except (OSError, IOError) blocks in
# these files when Python 2 is removed.
# In Python 3, IOError have been merged into OSError
# https://github.com/PyCQA/flake8-bugbear/issues/110
src/pip/_internal/utils/filesystem.py: B014
src/pip/_internal/network/cache.py: B014
src/pip/_internal/utils/misc.py: B014
[mypy]
follow_imports = silent
ignore_missing_imports = True
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def _handle_no_use_pep517(option, opt, value, parser):
# TODO: Move into a class that inherits from partial, currently does not
# work as mypy complains functools.partial is a generic class.
# This way we know we can ignore this option in docs auto generation
setattr(always_unzip, 'deprecated', True)
setattr(always_unzip, 'deprecated', True) # noqa: B010


def _handle_merge_hash(option, opt_str, value, parser):
Expand Down
4 changes: 3 additions & 1 deletion src/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def pretty_eta(self):
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()


Expand Down
11 changes: 8 additions & 3 deletions src/pip/_internal/commands/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from types import ModuleType
from typing import List, Optional, Dict
from optparse import Values
from pip._internal.configuration import Configuration

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -86,8 +87,12 @@ def get_vendor_version_from_module(module_name):

if not version:
# Try to find version in debundled module info
# The type for module.__file__ is Optional[str] in
# Python 2, and str in Python 3. The type: ignore is
# added to account for Python 2, instead of a cast
# and should be removed once we drop Python 2 support
pkg_set = pkg_resources.WorkingSet(
[os.path.dirname(getattr(module, '__file__'))]
[os.path.dirname(module.__file__)] # type: ignore
)
package = pkg_set.find(pkg_resources.Requirement.parse(module_name))
version = getattr(package, 'version', None)
Expand Down Expand Up @@ -164,9 +169,9 @@ def show_tags(options):


def ca_bundle_info(config):
# type: (Dict[str, str]) -> str
# type: (Configuration) -> str
levels = set()
for key, value in config.items():
for key, _ in config.items():
levels.add(key.split('.')[0])

if not levels:
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/utils/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,7 @@ def __init__(self, lines):

def readline(self):
try:
try:
return next(self._gen)
except NameError:
return self._gen.next()
return next(self._gen)
except StopIteration:
return ''

Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/vcs/subversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_revision(cls, location):
# 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
Expand Down
10 changes: 5 additions & 5 deletions src/pip/_internal/wheel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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
Expand All @@ -34,11 +34,11 @@

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
Expand Down