Update tooling
Marco Ricci

Marco Ricci commited on 2026-06-14 22:46:36
Zeige 9 geänderte Dateien mit 22 Einfügungen und 10 Löschungen.


`ruff` now checks for too many statements in a `try` block (PLW0717),
for non-trivial `__init__.py` files (RUF067), for explicitly comparing
floats with `__eq__` (RUF069) and for bad control flow in
a generator-based context manager (RUF075).  We document our intentional
RUF069 and RUF075 violations, we fix the other occurrences of RUF075,
and we ignore PLW0717 and RUF067 for now.
... ...
@@ -484,6 +484,11 @@ ignore = [
484 484
     # We catch type-ignore comments without specific code via the mypy
485 485
     # configuration, not via ruff.
486 486
     'PGH003',
487
+    # Provisionally ignore the `__init__.py` rule, until we can adapt our
488
+    # codebase.
489
+    'RUF067',
490
+    # Still undecided about this one.
491
+    'PLW0717',
487 492
 ]
488 493
 preview = true
489 494
 # We select here in the order of presentation on the ruff documentation
... ...
@@ -136,8 +136,10 @@ def format_key(key: tests.data.SSHTestKey) -> str:
136 136
         ]
137 137
         for sig in key.expected_signatures.values():
138 138
             expected_signature_lines.extend([
139
+                (
139 140
                     f"    {sig.signature_class!s}: "
140
-                "SSHTestKeyDeterministicSignature(\n",
141
+                    "SSHTestKeyDeterministicSignature(\n"
142
+                ),
141 143
                 "        signature=" + f(sig.signature) + ",\n",
142 144
                 "        derived_passphrase="
143 145
                 + f(sig.derived_passphrase)
... ...
@@ -512,7 +512,9 @@ def isolated_vault_exporter_config(
512 512
             ) -> Iterator[None]:  # pragma: no branch
513 513
                 oldpath = pathlib.Path.cwd().resolve()
514 514
                 os.chdir(newpath)
515
+                try:
515 516
                     yield
517
+                finally:
516 518
                     os.chdir(oldpath)
517 519
 
518 520
     with runner.isolated_filesystem():
... ...
@@ -377,8 +377,7 @@ class TestStubbedSSHAgentSocketRequests:
377 377
         with contextlib.ExitStack() as stack:
378 378
             monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
379 379
             monkeypatch.setenv("SSH_AUTH_SOCK", agent_class.ADDRESS)
380
-            agent = stack.enter_context(agent_class())
381
-            yield agent
380
+            yield stack.enter_context(agent_class())
382 381
 
383 382
     def test_query_extensions_base(self) -> None:
384 383
         """The base agent implements no extensions."""
... ...
@@ -330,7 +330,8 @@ class TestUserConfigurationFileOther:
330 330
                     main_config_str=main_config,
331 331
                 )
332 332
             )
333
-            yield monkeypatch
333
+            # If the setup blows up, then bubble the exception.
334
+            yield monkeypatch  # noqa: RUF075
334 335
             result = runner.invoke(
335 336
                 cli.derivepassphrase_vault,
336 337
                 ["--phrase", "--", DUMMY_SERVICE],
... ...
@@ -541,7 +541,8 @@ class TestExportConfigInvalid:
541 541
                     vault_config=config,
542 542
                 )
543 543
             )
544
-            yield command_line
544
+            # If the setup blows up, bubble the exception.
545
+            yield command_line  # noqa: RUF075
545 546
             result = runner.invoke(
546 547
                 cli.derivepassphrase_vault,
547 548
                 command_line,
... ...
@@ -743,7 +744,8 @@ class TestStoringConfigurationFailures:
743 744
                     "get_suitable_ssh_keys",
744 745
                     callables.suitable_ssh_keys,
745 746
                 )
746
-            yield monkeypatch
747
+            # If the setup blows up, bubble the exception.
748
+            yield monkeypatch  # noqa: RUF075
747 749
             result = runner.invoke(
748 750
                 cli.derivepassphrase_vault,
749 751
                 ["--config", *command_line],
... ...
@@ -271,7 +271,8 @@ class TestCLIFailures:
271 271
                     vault_key=vault_key,
272 272
                 )
273 273
             )
274
-            yield monkeypatch
274
+            # If the setup blows up, bubble the exception.
275
+            yield monkeypatch  # noqa: RUF075
275 276
             result = runner.invoke(
276 277
                 cli.derivepassphrase_export_vault,
277 278
                 command_line,
... ...
@@ -81,7 +81,7 @@ def test_js_truthiness(value: Any) -> None:
81 81
         value is not None  # noqa: PLR1714
82 82
         and value != False  # noqa: E712
83 83
         and value != 0
84
-        and value != 0.0
84
+        and value != 0.0  # noqa: RUF069
85 85
         and value != ""
86 86
         and not (isinstance(value, float) and math.isnan(value))
87 87
     )
... ...
@@ -832,7 +832,7 @@ class TestUtilities(TestVault):
832 832
             space=1,
833 833
             length=1,
834 834
         )
835
-        assert v._entropy() == 0.0
835
+        assert v._entropy() == 0.0  # noqa: RUF069
836 836
         assert v._estimate_sufficient_hash_length() > 0
837 837
 
838 838
     @Parametrize.SAMPLE_SERVICES_AND_PHRASES
... ...
@@ -849,7 +849,7 @@ class TestUtilities(TestVault):
849 849
         monkeypatch.setattr(
850 850
             v,
851 851
             "_estimate_sufficient_hash_length",
852
-            lambda *args, **kwargs: 1,  # noqa: ARG005
852
+            lambda *_args, **_kwargs: 1,
853 853
         )
854 854
         assert v._estimate_sufficient_hash_length() < len(self.phrase)
855 855
         assert v.generate(service) == expected
856 856