Skip to content

Commit a4933e4

Browse files
authored
Merge pull request #8405 from deveshks/flake8-bugbear-src
Fix "src/pip" to respect flake8-bugbear
2 parents cc48c07 + 8f1d808 commit a4933e4

File tree

9 files changed

+28
-19
lines changed

9 files changed

+28
-19
lines changed

news/AFD0EAD4-42B3-4EC1-A2AE-70D7513C8555.trivial

Whitespace-only changes.

setup.cfg

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ exclude =
2626
per-file-ignores =
2727
# B011: Do not call assert False since python -O removes these calls
2828
tests/*: B011
29-
# TODO: Remove this when fixing flake8-bugbear warnings in source
30-
src/pip/*: B007,B008,B009,B014,B305
29+
# TODO: Remove IOError from except (OSError, IOError) blocks in
30+
# these files when Python 2 is removed.
31+
# In Python 3, IOError have been merged into OSError
32+
# https://github.com/PyCQA/flake8-bugbear/issues/110
33+
src/pip/_internal/utils/filesystem.py: B014
34+
src/pip/_internal/network/cache.py: B014
35+
src/pip/_internal/utils/misc.py: B014
3136
[mypy]
3237
follow_imports = silent
3338
ignore_missing_imports = True

src/pip/_internal/cli/cmdoptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def _handle_no_use_pep517(option, opt, value, parser):
835835
# TODO: Move into a class that inherits from partial, currently does not
836836
# work as mypy complains functools.partial is a generic class.
837837
# This way we know we can ignore this option in docs auto generation
838-
setattr(always_unzip, 'deprecated', True)
838+
setattr(always_unzip, 'deprecated', True) # noqa: B010
839839

840840

841841
def _handle_merge_hash(option, opt_str, value, parser):

src/pip/_internal/cli/progress_bars.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def pretty_eta(self):
167167
def iter(self, it): # type: ignore
168168
for x in it:
169169
yield x
170-
self.next(len(x))
170+
# B305 is incorrectly raised here
171+
# https://github.com/PyCQA/flake8-bugbear/issues/59
172+
self.next(len(x)) # noqa: B305
171173
self.finish()
172174

173175

src/pip/_internal/commands/debug.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from types import ModuleType
2323
from typing import List, Optional, Dict
2424
from optparse import Values
25+
from pip._internal.configuration import Configuration
2526

2627
logger = logging.getLogger(__name__)
2728

@@ -86,8 +87,12 @@ def get_vendor_version_from_module(module_name):
8687

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

165170

166171
def ca_bundle_info(config):
167-
# type: (Dict[str, str]) -> str
172+
# type: (Configuration) -> str
168173
levels = set()
169-
for key, value in config.items():
174+
for key, _ in config.items():
170175
levels.add(key.split('.')[0])
171176

172177
if not levels:

src/pip/_internal/utils/filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _test_writable_dir_win(path):
155155
# and we can't use tempfile: http://bugs.python.org/issue22107
156156
basename = 'accesstest_deleteme_fishfingers_custard_'
157157
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
158-
for i in range(10):
158+
for _ in range(10):
159159
name = basename + ''.join(random.choice(alphabet) for _ in range(6))
160160
file = os.path.join(path, name)
161161
try:
@@ -190,7 +190,7 @@ def find_files(path, pattern):
190190
"""Returns a list of absolute paths of files beneath path, recursively,
191191
with filenames which match the UNIX-style shell glob pattern."""
192192
result = [] # type: List[str]
193-
for root, dirs, files in os.walk(path):
193+
for root, _, files in os.walk(path):
194194
matches = fnmatch.filter(files, pattern)
195195
result.extend(os.path.join(root, f) for f in matches)
196196
return result

src/pip/_internal/utils/misc.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,7 @@ def __init__(self, lines):
545545

546546
def readline(self):
547547
try:
548-
try:
549-
return next(self._gen)
550-
except NameError:
551-
return self._gen.next()
548+
return next(self._gen)
552549
except StopIteration:
553550
return ''
554551

src/pip/_internal/vcs/subversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_revision(cls, location):
5656
# Note: taken from setuptools.command.egg_info
5757
revision = 0
5858

59-
for base, dirs, files in os.walk(location):
59+
for base, dirs, _ in os.walk(location):
6060
if cls.dirname not in dirs:
6161
dirs[:] = []
6262
continue # no sense walking uncontrolled subdirs

src/pip/_internal/wheel_builder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
if MYPY_CHECK_RUNNING:
2525
from typing import (
26-
Any, Callable, Iterable, List, Optional, Pattern, Tuple,
26+
Any, Callable, Iterable, List, Optional, Tuple,
2727
)
2828

2929
from pip._internal.cache import WheelCache
@@ -34,11 +34,11 @@
3434

3535
logger = logging.getLogger(__name__)
3636

37+
_egg_info_re = re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', re.IGNORECASE)
3738

38-
def _contains_egg_info(
39-
s, _egg_info_re=re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)',
40-
re.IGNORECASE)):
41-
# type: (str, Pattern[str]) -> bool
39+
40+
def _contains_egg_info(s):
41+
# type: (str) -> bool
4242
"""Determine whether the string looks like an egg_info.
4343
4444
:param s: The string to parse. E.g. foo-2.1

0 commit comments

Comments
 (0)