Skip to content

Commit 794639b

Browse files
committed
Bump Ruff to v0.15.18 and address new lint violations
- Fix D421: reword property docstrings to noun phrases - Fix ISC004: parenthesize implicit string concatenation in collections; use single strings with # noqa: LN001 where readability is better - Drop now-redundant # noqa: D401 comments on property definitions - Suppress PLW0717, RUF067, S607 pending future fixes
1 parent 18f4ba8 commit 794639b

11 files changed

Lines changed: 102 additions & 92 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ repos:
6060
- id: no_optional
6161

6262
- repo: https://github.com/astral-sh/ruff-pre-commit.git
63-
rev: v0.13.3
63+
rev: v0.15.18
6464
hooks:
6565
- id: ruff
6666
args:
6767
# Ref: https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
6868
- --fix # NOTE: When `--fix` is used, linting should be before ruff-format
6969

7070
- repo: https://github.com/astral-sh/ruff-pre-commit.git
71-
rev: v0.13.3
71+
rev: v0.15.18
7272
hooks:
7373
- id: ruff-format
7474
alias: ruff-format-first-pass
@@ -80,7 +80,7 @@ repos:
8080
- id: add-trailing-comma
8181

8282
- repo: https://github.com/astral-sh/ruff-pre-commit.git
83-
rev: v0.13.3
83+
rev: v0.15.18
8484
hooks:
8585
- id: ruff-format
8686
alias: ruff-format-second-pass

.ruff.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ ignore = [
101101
"PLR6104", # non-augmented-assignment # FIXME
102102
"PLR6301", # no-self-use # FIXME / noqa
103103

104+
"PLW0717", # too-many-statements-in-try-clause # FIXME
105+
104106
"PLW1514", # unspecified-encoding # FIXME
105107

106108
"PTH100", # os-path-abspath # FIXME
@@ -115,6 +117,7 @@ ignore = [
115117
"PYI024", # collections-named-tuple # FIXME
116118

117119
"RUF005", # collection-literal-concatenation # FIXME
120+
"RUF067", # non-empty-init-module # FIXME
118121
"RUF012", # mutable-class-default # FIXME
119122
"RUF043", # pytest-raises-ambiguous-pattern # FIXME
120123
"RUF048", # map-int-version-parsing # FIXME
@@ -215,6 +218,7 @@ testing = [
215218
"S101", # Allow use of `assert` in test files
216219
"S404", # Allow importing 'subprocess' module to testing call external tools needed by these hooks
217220
"S603", # subprocess-without-shell-equals-true
221+
"S607", # start-process-with-partial-path # FIXME
218222
"SLF001", # Private member accessed
219223
]
220224

cheroot/connections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __len__(self):
8080

8181
@property
8282
def connections(self):
83-
"""Retrieve connections registered with the selector."""
83+
"""Connections registered with the selector."""
8484
with self._lock:
8585
mapping = self._selector.get_map() or {}
8686
for _, (_, sock_fd, _, conn) in mapping.items():
@@ -386,7 +386,7 @@ def close(self):
386386

387387
@property
388388
def _num_connections(self):
389-
"""Return the current number of connections.
389+
"""The current number of connections.
390390
391391
Includes all connections registered with the selector,
392392
minus one for the server socket, which is always registered

cheroot/server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,19 +1453,19 @@ def get_peer_creds(self): # LRU cached on per-instance basis, see __init__
14531453

14541454
@property
14551455
def peer_pid(self):
1456-
"""Return the id of the connected peer process."""
1456+
"""The id of the connected peer process."""
14571457
pid, _, _ = self.get_peer_creds()
14581458
return pid
14591459

14601460
@property
14611461
def peer_uid(self):
1462-
"""Return the user id of the connected peer process."""
1462+
"""The user id of the connected peer process."""
14631463
_, uid, _ = self.get_peer_creds()
14641464
return uid
14651465

14661466
@property
14671467
def peer_gid(self):
1468-
"""Return the group id of the connected peer process."""
1468+
"""The group id of the connected peer process."""
14691469
_, _, gid = self.get_peer_creds()
14701470
return gid
14711471

@@ -1495,13 +1495,13 @@ def resolve_peer_creds(self): # LRU cached on per-instance basis
14951495

14961496
@property
14971497
def peer_user(self):
1498-
"""Return the username of the connected peer process."""
1498+
"""The username of the connected peer process."""
14991499
user, _ = self.resolve_peer_creds()
15001500
return user
15011501

15021502
@property
15031503
def peer_group(self):
1504-
"""Return the group of the connected peer process."""
1504+
"""The group of the connected peer process."""
15051505
_, group = self.resolve_peer_creds()
15061506
return group
15071507

@@ -1750,7 +1750,7 @@ def __str__(self):
17501750

17511751
@property
17521752
def bind_addr(self):
1753-
"""Return the interface on which to listen for connections.
1753+
"""The interface on which to listen for connections.
17541754
17551755
For TCP sockets, a (host, port) tuple. Host values may be any
17561756
:term:`IPv4` or :term:`IPv6` address, or any valid hostname.
@@ -2234,7 +2234,7 @@ def interrupt(self):
22342234

22352235
@property
22362236
def _stopping_for_interrupt(self):
2237-
"""Return whether the server is responding to an interrupt."""
2237+
"""Whether the server is responding to an interrupt."""
22382238
return self._interrupt is _STOPPING_FOR_INTERRUPT
22392239

22402240
@interrupt.setter

cheroot/test/_pytest_plugin.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,11 @@ def pytest_load_initial_conftests(early_config, parser, args):
2121
# * https://github.com/pytest-dev/pytest/issues/5299
2222
early_config._inicache['filterwarnings'].extend(
2323
(
24-
'ignore:Exception in thread CP Server Thread-:'
25-
'pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception',
26-
'ignore:Exception in thread Thread-:'
27-
'pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception',
28-
'ignore:Exception ignored in. '
29-
'<socket.socket fd=-1, family=AddressFamily.AF_INET, '
30-
'type=SocketKind.SOCK_STREAM, proto=.:'
31-
'pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception',
32-
'ignore:Exception ignored in. '
33-
'<socket.socket fd=-1, family=AddressFamily.AF_INET6, '
34-
'type=SocketKind.SOCK_STREAM, proto=.:'
35-
'pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception',
36-
'ignore:Exception ignored in. '
37-
'<socket.socket fd=-1, family=AF_INET, '
38-
'type=SocketKind.SOCK_STREAM, proto=.:'
39-
'pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception',
40-
'ignore:Exception ignored in. '
41-
'<socket.socket fd=-1, family=AF_INET6, '
42-
'type=SocketKind.SOCK_STREAM, proto=.:'
43-
'pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception',
24+
'ignore:Exception in thread CP Server Thread-:pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception', # noqa: LN001
25+
'ignore:Exception in thread Thread-:pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception', # noqa: LN001
26+
'ignore:Exception ignored in. <socket.socket fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception', # noqa: LN001
27+
'ignore:Exception ignored in. <socket.socket fd=-1, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception', # noqa: LN001
28+
'ignore:Exception ignored in. <socket.socket fd=-1, family=AF_INET, type=SocketKind.SOCK_STREAM, proto=.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception', # noqa: LN001
29+
'ignore:Exception ignored in. <socket.socket fd=-1, family=AF_INET6, type=SocketKind.SOCK_STREAM, proto=.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception', # noqa: LN001
4430
),
4531
)

cheroot/test/test_conn.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ def testing_server(raw_testing_server, monkeypatch):
191191
continue
192192

193193
assert c_msg in raw_testing_server.error_log.ignored_msgs, (
194-
'Found error in the error log: '
195-
f"message = '{c_msg}', level = '{c_level}'\n"
196-
f'{c_traceback}',
194+
f"Found error in the error log: message = '{c_msg}', level = '{c_level}'\n{c_traceback}" # noqa: LN001
197195
)
198196

199197

@@ -790,17 +788,11 @@ def _read_request_line(self):
790788
(logging.WARNING, r'^socket\.error 666$'),
791789
(
792790
logging.INFO,
793-
'^Got a connection error while handling a connection '
794-
r'from .*:\d{1,5} \(666\)',
791+
r'^Got a connection error while handling a connection from .*:\d{1,5} \(666\)', # noqa: LN001
795792
),
796793
(
797794
logging.CRITICAL,
798-
r'A fatal exception happened\. Setting the server interrupt flag '
799-
r'to ConnectionResetError\(666,?\) and giving up\.\n\nPlease, '
800-
'report this on the Cheroot tracker at '
801-
r'<https://github\.com/cherrypy/cheroot/issues/new/choose>, '
802-
'providing a full reproducer with as much context and details '
803-
r'as possible\.$',
795+
r'A fatal exception happened\. Setting the server interrupt flag to ConnectionResetError\(666,?\) and giving up\.\n\nPlease, report this on the Cheroot tracker at <https://github\.com/cherrypy/cheroot/issues/new/choose>, providing a full reproducer with as much context and details as possible\.$', # noqa: LN001
804796
),
805797
)
806798

@@ -840,13 +832,11 @@ def _trigger_kb_intr(_req, _resp):
840832
expected_log_entries = (
841833
(
842834
logging.DEBUG,
843-
'^Got a server shutdown request while handling a connection '
844-
r'from .*:\d{1,5} \(simulated test handler keyboard interrupt\)$',
835+
r'^Got a server shutdown request while handling a connection from .*:\d{1,5} \(simulated test handler keyboard interrupt\)$', # noqa: LN001
845836
),
846837
(
847838
logging.DEBUG,
848-
'^Setting the server interrupt flag to KeyboardInterrupt'
849-
r"\('simulated test handler keyboard interrupt',?\)$",
839+
r"^Setting the server interrupt flag to KeyboardInterrupt\('simulated test handler keyboard interrupt',?\)$", # noqa: LN001
850840
),
851841
(
852842
logging.INFO,
@@ -913,9 +903,7 @@ def _trigger_scary_exc(_req, _resp):
913903
expected_log_entries = (
914904
(
915905
logging.ERROR,
916-
'^Unhandled error while processing an incoming connection '
917-
'SillyMistake'
918-
r"\('simulated unhandled exception 💣 in test handler',?\)$",
906+
r"^Unhandled error while processing an incoming connection SillyMistake\('simulated unhandled exception 💣 in test handler',?\)$", # noqa: LN001
919907
),
920908
(
921909
logging.INFO,
@@ -997,8 +985,7 @@ def _read_request_line(self):
997985
expected_log_entries = (
998986
(
999987
logging.ERROR,
1000-
'^Unhandled error while processing an incoming connection '
1001-
r'ScaryCrash\(666,?\)$',
988+
r'^Unhandled error while processing an incoming connection ScaryCrash\(666,?\)$', # noqa: LN001
1002989
),
1003990
(
1004991
logging.INFO,

cheroot/test/test_ssl.py

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -480,51 +480,75 @@ def test_tls_client_auth( # noqa: C901, WPS213 # FIXME
480480
expected_substrings += (
481481
(
482482
"bad handshake: SysCallError(10054, 'WSAECONNRESET')",
483-
"('Connection aborted.', "
484-
'OSError("(10054, \'WSAECONNRESET\')"))',
485-
"('Connection aborted.', "
486-
'OSError("(10054, \'WSAECONNRESET\')",))',
487-
"('Connection aborted.', "
488-
'error("(10054, \'WSAECONNRESET\')",))',
489-
"('Connection aborted.', "
490-
'ConnectionResetError(10054, '
491-
"'An existing connection was forcibly closed "
492-
"by the remote host', None, 10054, None))",
493-
"('Connection aborted.', "
494-
'error(10054, '
495-
"'An existing connection was forcibly closed "
496-
"by the remote host'))",
483+
(
484+
"('Connection aborted.', "
485+
'OSError("(10054, \'WSAECONNRESET\')"))'
486+
),
487+
(
488+
"('Connection aborted.', "
489+
'OSError("(10054, \'WSAECONNRESET\')",))'
490+
),
491+
(
492+
"('Connection aborted.', "
493+
'error("(10054, \'WSAECONNRESET\')",))'
494+
),
495+
(
496+
"('Connection aborted.', "
497+
'ConnectionResetError(10054, '
498+
"'An existing connection was forcibly closed "
499+
"by the remote host', None, 10054, None))"
500+
),
501+
(
502+
"('Connection aborted.', "
503+
'error(10054, '
504+
"'An existing connection was forcibly closed "
505+
"by the remote host'))"
506+
),
497507
)
498508
if IS_WINDOWS
499509
else (
500-
"('Connection aborted.', "
501-
'OSError("(104, \'ECONNRESET\')"))',
502-
"('Connection aborted.', "
503-
'OSError("(104, \'ECONNRESET\')",))',
510+
(
511+
"('Connection aborted.', "
512+
'OSError("(104, \'ECONNRESET\')"))'
513+
),
514+
(
515+
"('Connection aborted.', "
516+
'OSError("(104, \'ECONNRESET\')",))'
517+
),
504518
"('Connection aborted.', error(\"(104, 'ECONNRESET')\",))",
505-
"('Connection aborted.', "
506-
"ConnectionResetError(104, 'Connection reset by peer'))",
507-
"('Connection aborted.', "
508-
"error(104, 'Connection reset by peer'))",
519+
(
520+
"('Connection aborted.', "
521+
"ConnectionResetError(104, 'Connection reset by peer'))"
522+
),
523+
(
524+
"('Connection aborted.', "
525+
"error(104, 'Connection reset by peer'))"
526+
),
509527
)
510528
if (IS_GITHUB_ACTIONS_WORKFLOW and IS_LINUX)
511529
else (
512-
"('Connection aborted.', "
513-
"BrokenPipeError(32, 'Broken pipe'))",
530+
(
531+
"('Connection aborted.', "
532+
"BrokenPipeError(32, 'Broken pipe'))"
533+
),
514534
)
515535
)
516536

517537
if PY310_PLUS:
518538
# FIXME: Figure out what's happening and correct the problem
519539
expected_substrings += (
520-
'SSLError(SSLEOFError(8, '
521-
"'EOF occurred in violation of protocol (_ssl.c:",
540+
(
541+
'SSLError(SSLEOFError(8, '
542+
"'EOF occurred in violation of protocol (_ssl.c:"
543+
),
522544
)
523545
if IS_GITHUB_ACTIONS_WORKFLOW and IS_WINDOWS and PY310_PLUS:
524546
expected_substrings += (
525-
"('Connection aborted.', "
526-
'RemoteDisconnected('
527-
"'Remote end closed connection without response'))",
547+
(
548+
"('Connection aborted.', "
549+
'RemoteDisconnected('
550+
"'Remote end closed connection without response'))"
551+
),
528552
)
529553

530554
assert any(e in err_text for e in expected_substrings)
@@ -662,8 +686,10 @@ def test_ssl_env( # noqa: C901 # FIXME
662686
pytest.xfail(
663687
'\n'.join(
664688
(
665-
'Sometimes this test fails due to '
666-
'a socket.socket ResourceWarning:',
689+
(
690+
'Sometimes this test fails due to '
691+
'a socket.socket ResourceWarning:'
692+
),
667693
msg,
668694
),
669695
),

cheroot/test/webtest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class WebCase(unittest.TestCase):
120120

121121
@property
122122
def _Conn(self):
123-
"""Return HTTPConnection or HTTPSConnection based on self.scheme.
123+
"""HTTPConnection or HTTPSConnection based on self.scheme.
124124
125125
* from :py:mod:`python:http.client`.
126126
"""
@@ -305,7 +305,7 @@ def _handlewebError(self, msg): # noqa: C901 # FIXME
305305
sys.stdout.flush()
306306

307307
@property
308-
def status_code(self): # noqa: D401; irrelevant for properties
308+
def status_code(self):
309309
"""Integer HTTP status code."""
310310
return int(self.status[:3])
311311

cheroot/workers/threadpool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ def start(self):
299299
self.grow(self.min)
300300

301301
@property
302-
def idle(self): # noqa: D401; irrelevant for properties
303-
"""Number of worker threads which are idle. Read-only.""" # noqa: D401
302+
def idle(self):
303+
"""Number of worker threads which are idle. Read-only."""
304304
idles = len([t for t in self._threads if t.conn is None])
305305
return max(idles - len(self._pending_shutdowns), 0)
306306

@@ -432,5 +432,5 @@ def _clear_threads(self):
432432

433433
@property
434434
def qsize(self):
435-
"""Return the queue size."""
435+
"""The queue size."""
436436
return self._queue.qsize()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Bumped Ruff to v0.15.18, which introduces new rules:
2+
1. Property docstrings must now use noun phrases rather than verb phrases
3+
(D421, e.g. "The queue size." not "Return the queue size."),
4+
2. Implicit string concatenation inside collection literals must be
5+
parenthesized (ISC004).
6+
Three further new rules are suppressed pending fixes: too many statements
7+
in a try clause (PLW0717), non-empty ``__init__`` modules (RUF067), and
8+
starting a process with a partial executable path (S607)
9+
-- by :user:`julianz-`.

0 commit comments

Comments
 (0)