summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.flake810
-rw-r--r--Makefile15
-rw-r--r--psutil/__init__.py2
-rw-r--r--psutil/_compat.py10
-rwxr-xr-xpsutil/tests/test_misc.py2
-rwxr-xr-xscripts/internal/convert_readme.py2
-rwxr-xr-xscripts/internal/print_announce.py2
7 files changed, 23 insertions, 20 deletions
diff --git a/.flake8 b/.flake8
index 1244cd48..20025785 100644
--- a/.flake8
+++ b/.flake8
@@ -1,15 +1,17 @@
# Configuration file for flake 8. This is used by "make lint" and by the
# GIT commit hook script.
-# T001 = print() statement
[flake8]
ignore =
- # line break after binary operator
- W504
+ W504 # line break after binary operator
+ # --- flake8-bugbear
+ B007 # Loop control variable 'keyword' not used within the loop body. If this is intended, start the name with an underscore.
+ B014 # Redundant exception types in `except (IOError, OSError) as err:`. Write `except OSError as err:`, which catches exactly the same exceptions.
+ B008 # Do not perform function calls in argument defaults.
per-file-ignores =
+ # T001 = print() statement
setup.py:T001
scripts/*:T001
- scripts/internal/convert_readme.py:E501,T001
psutil/tests/runner.py:T001
psutil/tests/test_memleaks.py:T001
.github/workflows/*:T001
diff --git a/Makefile b/Makefile
index d544dd1c..838d7b47 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ DEPS = \
coverage \
flake8 \
flake8-print \
+ flake8-bugbear \
isort \
pyperf \
pypinfo \
@@ -188,19 +189,19 @@ test-coverage: ## Run test coverage.
# Linters
# ===================================================================
-check-flake8: ## Run flake8 linter.
+flake8: ## Run flake8 linter.
@git ls-files '*.py' | xargs $(PYTHON) -m flake8 --config=.flake8
-check-imports: ## Run isort linter.
+isort: ## Run isort linter.
@git ls-files '*.py' | xargs $(PYTHON) -m isort --settings=.isort.cfg --check-only
-check-c-code: ## Run C linter.
+c-linter: ## Run C linter.
@git ls-files '*.c' '*.h' | xargs $(PYTHON) scripts/internal/clinter.py
-check-all: ## Run all linters
- ${MAKE} check-flake8
- ${MAKE} check-imports
- ${MAKE} check-c-code
+lint-all: ## Run all linters
+ ${MAKE} flake8
+ ${MAKE} isort
+ ${MAKE} c-linter
# ===================================================================
# Fixers
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 2f2a593d..1ba0c19f 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -228,7 +228,7 @@ _SENTINEL = object()
if (int(__version__.replace('.', '')) !=
getattr(_psplatform.cext, 'version', None)):
msg = "version conflict: %r C extension module was built for another " \
- "version of psutil" % getattr(_psplatform.cext, "__file__")
+ "version of psutil" % _psplatform.cext.__file__
if hasattr(_psplatform.cext, 'version'):
msg += " (%s instead of %s)" % (
'.'.join([x for x in str(_psplatform.cext.version)]), __version__)
diff --git a/psutil/_compat.py b/psutil/_compat.py
index 251e595f..52e762b1 100644
--- a/psutil/_compat.py
+++ b/psutil/_compat.py
@@ -232,8 +232,8 @@ except ImportError:
return self.hashvalue
def _make_key(args, kwds, typed,
- kwd_mark=(object(), ),
- fasttypes=set((int, str, frozenset, type(None))),
+ kwd_mark=(_SENTINEL, ),
+ fasttypes=set((int, str, frozenset, type(None))), # noqa
sorted=sorted, tuple=tuple, type=type, len=len):
key = args
if kwds:
@@ -442,9 +442,9 @@ try:
except ImportError:
@contextlib.contextmanager
def redirect_stderr(new_target):
- original = getattr(sys, "stderr")
+ original = sys.stderr
try:
- setattr(sys, "stderr", new_target)
+ sys.stderr = new_target
yield new_target
finally:
- setattr(sys, "stderr", original)
+ sys.stderr = original
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index add9646e..90b49c1f 100755
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -402,7 +402,7 @@ class TestCommonModule(PsutilTestCase):
supports_ipv6.cache_clear()
assert s.called
else:
- with self.assertRaises(Exception):
+ with self.assertRaises(socket.error):
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
try:
sock.bind(("::1", 0))
diff --git a/scripts/internal/convert_readme.py b/scripts/internal/convert_readme.py
index cca7dcb0..81f7bdb6 100755
--- a/scripts/internal/convert_readme.py
+++ b/scripts/internal/convert_readme.py
@@ -36,7 +36,7 @@ Sponsors
`Add your logo <https://github.com/sponsors/giampaolo>`__.
-Example usages"""
+Example usages""" # noqa
def main():
diff --git a/scripts/internal/print_announce.py b/scripts/internal/print_announce.py
index fae53ea3..c2113f36 100755
--- a/scripts/internal/print_announce.py
+++ b/scripts/internal/print_announce.py
@@ -83,7 +83,7 @@ def get_changes():
block = []
# eliminate the part preceding the first block
- for i, line in enumerate(lines):
+ for line in lines:
line = lines.pop(0)
if line.startswith('===='):
break