提交 76a13010 编写于 作者: D Devesh Kumar Singh

Fix src/pip with flake8-bugbear

上级 0dbd3938
......@@ -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()
......
......@@ -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:
......
......@@ -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
......
......@@ -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 ''
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册