Rewrite test data initializers for nicer API docs
Marco Ricci

Marco Ricci commited on 2026-06-16 19:55:01
Zeige 1 geänderte Dateien mit 10 Einfügungen und 9 Löschungen.


In attribute declarations, `griffe`/`mkdocstring-python` elides the
object on which the outermost method is called (but correctly autolinks
the method itself).  This looks good if the initializer is something
like `base64.b64_decode(data)` (which gets shortened to
`b64_decode(data)`), and terrible if the initializer is something like
`base64.b64_decode(data).decode()` (which gets shortened to `decode()`).
So, to get nicer API docs, rewrite some obvious cases where the object
would otherwise be elided in the "class-bound method + self argument"
style instead.
... ...
@@ -20,6 +20,7 @@ system itself is also in the `tests.machinery` module, not here.
20 20
 from __future__ import annotations
21 21
 
22 22
 import base64
23
+import copy
23 24
 import enum
24 25
 from typing import TYPE_CHECKING, cast
25 26
 
... ...
@@ -1457,17 +1458,17 @@ DUMMY_PASSPHRASE = "my secret passphrase"
1457 1458
 """A standard/sample passphrase."""
1458 1459
 DUMMY_KEY1 = SUPPORTED_KEYS["ed25519"].public_key_data
1459 1460
 """A sample universally supported SSH test key (in wire format)."""
1460
-DUMMY_KEY1_B64 = base64.standard_b64encode(DUMMY_KEY1).decode("ASCII")
1461
+DUMMY_KEY1_B64 = bytes.decode(base64.standard_b64encode(DUMMY_KEY1), "ASCII")
1461 1462
 """
1462 1463
 A sample universally supported SSH test key (in `authorized_keys` format).
1463 1464
 """
1464 1465
 DUMMY_KEY2 = SUPPORTED_KEYS["rsa"].public_key_data
1465 1466
 """A second supported SSH test key (in wire format)."""
1466
-DUMMY_KEY2_B64 = base64.standard_b64encode(DUMMY_KEY2).decode("ASCII")
1467
+DUMMY_KEY2_B64 = bytes.decode(base64.standard_b64encode(DUMMY_KEY2), "ASCII")
1467 1468
 """A second supported SSH test key (in `authorized_keys` format)."""
1468 1469
 DUMMY_KEY3 = SUPPORTED_KEYS["ed448"].public_key_data
1469 1470
 """A third supported SSH test key (in wire format)."""
1470
-DUMMY_KEY3_B64 = base64.standard_b64encode(DUMMY_KEY3).decode("ASCII")
1471
+DUMMY_KEY3_B64 = bytes.decode(base64.standard_b64encode(DUMMY_KEY3), "ASCII")
1471 1472
 """A third supported SSH test key (in `authorized_keys` format)."""
1472 1473
 DUMMY_CONFIG_SETTINGS_AS_CONSTRUCTOR_ARGS = cast(
1473 1474
     "_types.VaultConstructorArgs",
... ...
@@ -1527,13 +1528,13 @@ and encrypted with [`VAULT_MASTER_KEY`][].
1527 1528
 """
1528 1529
 VAULT_V02_CONFIG_DATA = {
1529 1530
     "global": {
1530
-        "phrase": DUMMY_PASSPHRASE.rstrip("\n"),
1531
+        "phrase": str.rstrip(DUMMY_PASSPHRASE, "\n"),
1531 1532
     },
1532 1533
     "services": {
1533 1534
         "(meta)": {
1534 1535
             "notes": "This config was originally in v0.2 format.",
1535 1536
         },
1536
-        DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1537
+        DUMMY_SERVICE: copy.copy(DUMMY_CONFIG_SETTINGS),
1537 1538
     },
1538 1539
 }
1539 1540
 """
... ...
@@ -1547,13 +1548,13 @@ and encrypted with [`VAULT_MASTER_KEY`][].
1547 1548
 """
1548 1549
 VAULT_V03_CONFIG_DATA = {
1549 1550
     "global": {
1550
-        "phrase": DUMMY_PASSPHRASE.rstrip("\n"),
1551
+        "phrase": str.rstrip(DUMMY_PASSPHRASE, "\n"),
1551 1552
     },
1552 1553
     "services": {
1553 1554
         "(meta)": {
1554 1555
             "notes": "This config was originally in v0.3 format.",
1555 1556
         },
1556
-        DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1557
+        DUMMY_SERVICE: copy.copy(DUMMY_CONFIG_SETTINGS),
1557 1558
     },
1558 1559
 }
1559 1560
 """
... ...
@@ -1619,13 +1620,13 @@ and then encoded in base64.
1619 1620
 """
1620 1621
 VAULT_STOREROOM_CONFIG_DATA = {
1621 1622
     "global": {
1622
-        "phrase": DUMMY_PASSPHRASE.rstrip("\n"),
1623
+        "phrase": str.rstrip(DUMMY_PASSPHRASE, "\n"),
1623 1624
     },
1624 1625
     "services": {
1625 1626
         "(meta)": {
1626 1627
             "notes": "This config was originally in storeroom format.",
1627 1628
         },
1628
-        DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1629
+        DUMMY_SERVICE: copy.copy(DUMMY_CONFIG_SETTINGS),
1629 1630
     },
1630 1631
 }
1631 1632
 """
1632 1633