Skip to content

Commit

Permalink
ruff: use preview that adds new checks
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 8, 2024
1 parent 6d50bf7 commit 54cf4ae
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 17 deletions.
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#
# Copyright (C) 2007 Giampaolo Rodola' <[email protected]>.
# Use of this source code is governed by MIT license that can be
# found in the LICENSE file.

# pyftpdlib documentation build configuration file, created by
# sphinx-quickstart on Wed Oct 19 21:54:30 2016.
#
Expand Down
4 changes: 4 additions & 0 deletions pyftpdlib/_compat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2007 Giampaolo Rodola' <[email protected]>.
# Use of this source code is governed by MIT license that can be
# found in the LICENSE file.

"""
Compatibility module similar to six lib, which helps maintaining
a single code base working with both python 2.7 and 3.x.
Expand Down
10 changes: 5 additions & 5 deletions pyftpdlib/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def handle_timeout(self):
def handle_error(self):
"""Called to handle any uncaught exceptions."""
try:
raise
raise # noqa: PLE0704
except Exception:
logger.error(traceback.format_exc())
try:
Expand Down Expand Up @@ -536,7 +536,7 @@ def handle_close(self):
def handle_error(self):
"""Called to handle any uncaught exceptions."""
try:
raise
raise # noqa: PLE0704
except (socket.gaierror, socket.error):
pass
except Exception:
Expand Down Expand Up @@ -848,7 +848,7 @@ def handle_timeout(self):
def handle_error(self):
"""Called when an exception is raised and not otherwise handled."""
try:
raise
raise # noqa: PLE0704
# an error could occur in case we fail reading / writing
# from / to file (e.g. file system gets full)
except _FileReadWriteError as err:
Expand Down Expand Up @@ -3276,7 +3276,7 @@ def handle_write_event(self):
def handle_error(self):
self._error = True
try:
raise
raise # noqa: PLE0704
except Exception:
self.log_exception(self)
# when facing an unhandled exception in here it's better
Expand Down Expand Up @@ -3604,7 +3604,7 @@ def process_command(self, cmd, *args, **kwargs):
def close(self):
SSLConnection.close(self)
FTPHandler.close(self)

# --- new methods

def handle_failed_ssl_handshake(self):
Expand Down
2 changes: 1 addition & 1 deletion pyftpdlib/ioloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def bind_af_unspecified(self, addr):
"""
assert self.socket is None
host, port = addr
if host == "":
if not host:
# When using bind() "" is a symbolic name meaning all
# available interfaces. People might not know we're
# using getaddrinfo() internally, which uses None
Expand Down
2 changes: 1 addition & 1 deletion pyftpdlib/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def handle_accepted(self, sock, addr):
def handle_error(self):
"""Called to handle any uncaught exceptions."""
try:
raise
raise # noqa: PLE0704
except Exception:
logger.error(traceback.format_exc())
self.close()
Expand Down
4 changes: 2 additions & 2 deletions pyftpdlib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ def wrapper(cls, *args, **kwargs):
cls.setUp()
continue
if PY3:
raise exc
raise exc # noqa: PLE0704
else:
raise
raise # noqa: PLE0704

# This way the user of the decorated function can change config
# parameters.
Expand Down
2 changes: 1 addition & 1 deletion pyftpdlib/test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,7 @@ def test_port_v4(self):
resp = self.cmdresp('port %s,1,1' % self.HOST.replace('.', ','))
self.assertEqual(resp[:3], '501')
self.assertIn('privileged port', resp)
if "1.2.3.4" != self.HOST:
if self.HOST != "1.2.3.4":
resp = self.cmdresp('port 1,2,3,4,4,4')
assert 'foreign address' in resp, resp

Expand Down
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# https://beta.ruff.rs/docs/settings/
target-version = "py37"
line-length = 79

[tool.ruff.lint]
preview = true
select = [
"ALL", # to get a list of all values: `python3 -m ruff linter`
]
Expand All @@ -11,6 +14,7 @@ ignore = [
"ARG", # flake8-unused-arguments
"B007", # Loop control variable `x` not used within loop body
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` (PYTHON2.7 COMPAT)
"B904", # Use `raise from` to specify exception cause (PYTHON2.7 COMPAT)
"BLE001", # Do not catch blind exception: `Exception`
"C4", # flake8-comprehensions (PYTHON2.7 COMPAT)
# "C408", # Unnecessary `dict` call (rewrite as a literal)
Expand All @@ -20,9 +24,12 @@ ignore = [
"DTZ", # flake8-datetimez
"EM", # flake8-errmsg
"ERA001", # Found commented-out code
"F841", # Local variable `wr` is assigned to but never used
"FBT", # flake8-boolean-trap
"FIX", # Line contains TODO / XXX / ..., consider resolving the issue
"FLY", # flynt (PYTHON2.7 COMPAT)
"FURB101", # `open` and `read` should be replaced by `Path(x).read_text()`
"FURB113", # Use `s.extend(...)` instead of repeatedly calling `s.append()`
"INP", # flake8-no-pep420
"N801", # Class name `async_chat` should use CapWords convention (ASYNCORE COMPAT)
"N802", # Function name X should be lowercase.
Expand All @@ -32,6 +39,8 @@ ignore = [
"N818", # Exception name `FooBar` should be named with an Error suffix
"PERF", # Perflint
"PGH004", # Use specific rule codes when using `noqa`
"PLC0415", # `import` should be at the top-level of a file
"PLC2701", # Private name import `_winreg`
"PLR", # pylint
"PLW", # pylint
"PT", # flake8-pytest-style
Expand All @@ -48,23 +57,22 @@ ignore = [
"SLF", # flake8-self
"TD", # all TODOs, XXXs, etc.
"TRY003", # Avoid specifying long messages outside the exception class
"TRY200", # Use `raise from` to specify exception cause (PYTHON2.7 COMPAT)
"TRY300", # Consider moving this statement to an `else` block
"TRY301", # Abstract `raise` to an inner function
"UP010", # [*] Unnecessary `__future__` import `print_function` for target Python version (PYTHON2.7 COMPAT)
"UP024", # [*] Replace aliased errors with `OSError` (PYTHON2.7 COMPAT)
"UP031", # [*] Use format specifiers instead of percent format
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
".git_pre_commit.py" = ["T201"] # T201 == print()
"demo/*" = ["T201"]
"doc/*" = ["T201"]
"pyftpdlib/test/runner.py" = ["T201"]
"scripts/*" = ["T201"]
"setup.py" = ["T201"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
# https://beta.ruff.rs/docs/settings/#isort
force-single-line = true # one import per line
lines-after-imports = 2
Expand Down
2 changes: 1 addition & 1 deletion scripts/internal/print_announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_changes():
break
lines.pop(0)

for i, line in enumerate(lines):
for line in lines:
line = lines.pop(0)
line = line.rstrip()
if re.match(r"^- \d+_: ", line):
Expand Down
4 changes: 2 additions & 2 deletions scripts/internal/winmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def safe_rmtree(path):
def onerror(fun, path, excinfo):
exc = excinfo[1]
if exc.errno != errno.ENOENT:
raise
raise # noqa: PLE0704

existed = os.path.isdir(path)
shutil.rmtree(path, onerror=onerror)
Expand Down Expand Up @@ -172,7 +172,7 @@ def safe_rmtree(path):
def onerror(fun, path, excinfo):
exc = excinfo[1]
if exc.errno != errno.ENOENT:
raise
raise # noqa: PLE0704

existed = os.path.isdir(path)
shutil.rmtree(path, onerror=onerror)
Expand Down

0 comments on commit 54cf4ae

Please sign in to comment.