Skip to content

Commit e53ada3

Browse files
romanlutzCopilot
andauthored
DOC: Replace reST cross-reference roles in docstrings with plain backticks (#1782)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f3e012d commit e53ada3

18 files changed

Lines changed: 82 additions & 54 deletions

.github/instructions/style-guide.instructions.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,33 @@ def calculate_score(
192192
"""
193193
```
194194

195+
### Code references in docstrings
196+
197+
The PyRIT docs build uses **MyST** (Markdown-flavoured), not reStructuredText.
198+
Do **not** use reST cross-reference roles in docstrings or module comments —
199+
they render as raw text under MyST and are inconsistent with the rest of the
200+
codebase, which uses plain double-backtick code spans for symbol names.
201+
202+
```python
203+
# WRONG — reST roles render as literal `:class:\`SeedPrompt\`` under MyST
204+
"""Returns a :class:`SeedPrompt` instance."""
205+
"""Delegate to :func:`download_files_async` (deprecated alias)."""
206+
"""See :meth:`PromptTarget.apply_capabilities` for details."""
207+
208+
# CORRECT — plain double-backtick code span (matches existing convention)
209+
"""Returns a ``SeedPrompt`` instance."""
210+
"""Delegate to ``download_files_async`` (deprecated alias)."""
211+
"""See ``PromptTarget.apply_capabilities`` for details."""
212+
```
213+
214+
Roles to avoid include `:class:`, `:func:`, `:meth:`, `:mod:`, `:attr:`,
215+
`:data:`, `:exc:`, `:obj:`, `:ref:`, and any `:py:*:` variants
216+
(e.g. `:py:class:`, `:py:func:`).
217+
218+
If you genuinely need a Sphinx cross-reference (rare in PyRIT — most
219+
docstrings just name the symbol in backticks), use the MyST role syntax
220+
`` {class}`Name` `` instead. The default, though, is plain double-backticks.
221+
195222
### Class-Level Constants
196223
- Define constants as class attributes, not module-level
197224
- Use UPPER_CASE naming for constants
@@ -454,6 +481,7 @@ Before committing code, ensure:
454481
- [ ] All functions have complete type annotations
455482
- [ ] Functions with >1 parameter use keyword-only arguments
456483
- [ ] Docstrings include parameter types
484+
- [ ] Docstrings use plain double-backtick code spans for symbol references (no reST roles)
457485
- [ ] Enums are used instead of Literals
458486
- [ ] Functions are focused and under 20 lines
459487
- [ ] Error messages are helpful and specific

pyrit/auth/azure_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ async def get_speech_config_async(
443443
"""
444444
Get the speech config, resolving a callable token provider if one is provided.
445445
446-
This is the async counterpart to :func:`get_speech_config`. When a callable
446+
This is the async counterpart to ``get_speech_config``. When a callable
447447
``token_provider`` is supplied, it is invoked (and awaited if async) to obtain
448448
a token, which is then used with the ``aad#{resource_id}#{token}`` auth format.
449-
Otherwise, it delegates to the synchronous :func:`get_speech_config`.
449+
Otherwise, it delegates to the synchronous ``get_speech_config``.
450450
451451
Args:
452452
token_provider (Callable | None): An optional sync or async callable that returns a token string.

pyrit/common/data_url_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def convert_local_image_to_data_url_async(image_path: str) -> str:
4747

4848
async def convert_local_image_to_data_url(image_path: str) -> str:
4949
"""
50-
Delegate to :func:`convert_local_image_to_data_url_async` (deprecated alias).
50+
Delegate to ``convert_local_image_to_data_url_async`` (deprecated alias).
5151
5252
Returns:
5353
str: A string containing the MIME type and the base64-encoded data of the image, formatted as a data URL.

pyrit/common/display_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def display_image_response_async(response_piece: MessagePiece) -> None:
5858

5959

6060
async def display_image_response(response_piece: MessagePiece) -> None:
61-
"""Delegate to :func:`display_image_response_async` (deprecated alias)."""
61+
"""Delegate to ``display_image_response_async`` (deprecated alias)."""
6262
print_deprecation_message(
6363
old_item="pyrit.common.display_response.display_image_response",
6464
new_item="pyrit.common.display_response.display_image_response_async",

pyrit/common/download_hf_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async def download_with_limit_async(url: str) -> None:
129129

130130

131131
async def download_specific_files(model_id: str, file_patterns: list[str] | None, token: str, cache_dir: Path) -> None:
132-
"""Delegate to :func:`download_specific_files_async` (deprecated alias)."""
132+
"""Delegate to ``download_specific_files_async`` (deprecated alias)."""
133133
print_deprecation_message(
134134
old_item="pyrit.common.download_hf_model.download_specific_files",
135135
new_item="pyrit.common.download_hf_model.download_specific_files_async",
@@ -140,7 +140,7 @@ async def download_specific_files(model_id: str, file_patterns: list[str] | None
140140

141141
async def download_chunk(url: str, headers: dict[str, str], start: int, end: int, client: httpx.AsyncClient) -> bytes:
142142
"""
143-
Delegate to :func:`download_chunk_async` (deprecated alias).
143+
Delegate to ``download_chunk_async`` (deprecated alias).
144144
145145
Returns:
146146
The content of the downloaded chunk.
@@ -154,7 +154,7 @@ async def download_chunk(url: str, headers: dict[str, str], start: int, end: int
154154

155155

156156
async def download_file(url: str, token: str, download_dir: Path, num_splits: int) -> None:
157-
"""Delegate to :func:`download_file_async` (deprecated alias)."""
157+
"""Delegate to ``download_file_async`` (deprecated alias)."""
158158
print_deprecation_message(
159159
old_item="pyrit.common.download_hf_model.download_file",
160160
new_item="pyrit.common.download_hf_model.download_file_async",
@@ -166,7 +166,7 @@ async def download_file(url: str, token: str, download_dir: Path, num_splits: in
166166
async def download_files(
167167
urls: list[str], token: str, download_dir: Path, num_splits: int = 3, parallel_downloads: int = 4
168168
) -> None:
169-
"""Delegate to :func:`download_files_async` (deprecated alias)."""
169+
"""Delegate to ``download_files_async`` (deprecated alias)."""
170170
print_deprecation_message(
171171
old_item="pyrit.common.download_hf_model.download_files",
172172
new_item="pyrit.common.download_hf_model.download_files_async",

pyrit/prompt_converter/add_text_image_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AddTextImageConverter(_BaseImageTextConverter):
2323
"""
2424
Adds a string to an image and wraps the text into multiple lines if necessary.
2525
26-
This class is similar to :class:`AddImageTextConverter` except
26+
This class is similar to ``AddImageTextConverter`` except
2727
we pass in text as an argument to the constructor as opposed to an image file path.
2828
"""
2929

pyrit/prompt_converter/azure_speech_audio_to_text_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def recognize_audio(self, audio_bytes: bytes) -> str:
176176
Recognize audio file and return transcribed text.
177177
178178
.. deprecated::
179-
Use :meth:`convert_async` instead, which resolves token providers correctly.
179+
Use ``convert_async`` instead, which resolves token providers correctly.
180180
This method does not support callable token providers.
181181
182182
Args:

pyrit/prompt_target/common/discover_target_capabilities.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
77
This module exposes two complementary probes:
88
9-
* :func:`_discover_capability_flags_async` discovers the boolean capability flags
10-
defined on :class:`TargetCapabilities` (e.g. ``supports_system_prompt``,
9+
* ``_discover_capability_flags_async`` discovers the boolean capability flags
10+
defined on ``TargetCapabilities`` (e.g. ``supports_system_prompt``,
1111
``supports_multi_message_pieces``). For each capability that has a probe
1212
defined, a minimal request is sent to the target. If the request succeeds,
1313
the capability is included in the returned set. Capabilities without a
1414
registered probe fall back to the target's declared native support from
1515
``target.capabilities``.
16-
* :func:`_discover_input_modalities_async` discovers which input modality
16+
* ``_discover_input_modalities_async`` discovers which input modality
1717
combinations a target actually supports by sending a minimal test request
1818
for each combination declared in ``TargetCapabilities.input_modalities``.
1919
@@ -120,7 +120,7 @@ def _permissive_configuration(
120120
Temporarily replace ``target``'s configuration with one that declares every
121121
boolean capability as natively supported.
122122
123-
This bypasses :meth:`PromptTarget._validate_request`, which would otherwise
123+
This bypasses ``PromptTarget._validate_request``, which would otherwise
124124
short-circuit probes for capabilities the target declares as unsupported
125125
before any API call is made. The original configuration is restored on exit.
126126
@@ -182,9 +182,9 @@ def _probe_metadata(extra: dict[str, str | int] | None = None) -> dict[str, str
182182

183183
def _user_text_piece(*, value: str, conversation_id: str) -> MessagePiece:
184184
"""
185-
Build a single user-role text :class:`MessagePiece` for use in a probe.
185+
Build a single user-role text ``MessagePiece`` for use in a probe.
186186
187-
The piece's ``prompt_metadata`` is tagged with :data:`PROBE_METADATA_KEY`
187+
The piece's ``prompt_metadata`` is tagged with ``PROBE_METADATA_KEY``
188188
so that consumers aggregating memory can filter out probe-written rows.
189189
190190
Args:
@@ -229,7 +229,7 @@ async def _send_and_check_async(
229229
retries (int): Number of additional attempts after the first failure.
230230
Only transient errors are retried; non-retryable errors and
231231
non-error responses are final. Retry attempts use exponential
232-
backoff starting at :data:`DEFAULT_PROBE_RETRY_BACKOFF_SECONDS`.
232+
backoff starting at ``DEFAULT_PROBE_RETRY_BACKOFF_SECONDS``.
233233
Defaults to 1.
234234
label (str): Short label used in log messages. Defaults to
235235
``"Capability probe"``.
@@ -291,8 +291,8 @@ async def _probe_system_prompt_async(target: PromptTarget, timeout_s: float, ret
291291
"""
292292
Probe whether ``target`` accepts a system prompt followed by a user message.
293293
294-
Writes a system-role :class:`MessagePiece` directly to ``target._memory``
295-
rather than calling :meth:`pyrit.prompt_target.PromptChatTarget.set_system_prompt`
294+
Writes a system-role ``MessagePiece`` directly to ``target._memory``
295+
rather than calling ``pyrit.prompt_target.PromptChatTarget.set_system_prompt``
296296
(which is only defined on ``PromptChatTarget`` subclasses anyway).
297297
``set_system_prompt`` can be overridden by subclasses (e.g. mocks) to do
298298
nothing or to perform extra work, which would mask whether the underlying
@@ -526,10 +526,10 @@ async def _discover_capability_flags_async(
526526
Args:
527527
target (PromptTarget): The target to probe.
528528
capabilities (Iterable[CapabilityName] | None): Capabilities to check.
529-
Defaults to every member of :class:`CapabilityName`.
529+
Defaults to every member of ``CapabilityName``.
530530
per_probe_timeout_s (float): Per-attempt timeout (seconds) applied to
531531
each probe request. Defaults to
532-
:data:`DEFAULT_PROBE_TIMEOUT_SECONDS`.
532+
``DEFAULT_PROBE_TIMEOUT_SECONDS``.
533533
retries (int): Number of additional attempts after the first failure
534534
for each probe. Only exceptions/timeouts are retried; an explicit
535535
error response is final. Set to ``0`` to disable retries.
@@ -593,7 +593,7 @@ async def _discover_capability_flags_async(
593593

594594
# Default mapping of non-text modalities to packaged probe assets. Callers can
595595
# override via the ``test_assets`` parameter of
596-
# :func:`_discover_input_modalities_async`. Modalities whose assets do not exist
596+
# ``_discover_input_modalities_async``. Modalities whose assets do not exist
597597
# on disk are skipped (logged and excluded from the result).
598598
DEFAULT_TEST_ASSETS: dict[PromptDataType, str] = {
599599
"audio_path": str(_TARGET_CAPABILITIES_DATASET_PATH / "probe_audio.wav"),
@@ -622,11 +622,11 @@ async def _discover_input_modalities_async(
622622
declared in ``target.capabilities.input_modalities``.
623623
test_assets (dict[PromptDataType, str] | None): Mapping from
624624
non-text modality to a file path used as the probe payload.
625-
Defaults to :data:`DEFAULT_TEST_ASSETS`. Combinations whose
625+
Defaults to ``DEFAULT_TEST_ASSETS``. Combinations whose
626626
non-text assets are missing on disk are skipped.
627627
per_probe_timeout_s (float): Per-attempt timeout (seconds) applied to
628628
each probe request. Defaults to
629-
:data:`DEFAULT_PROBE_TIMEOUT_SECONDS`.
629+
``DEFAULT_PROBE_TIMEOUT_SECONDS``.
630630
retries (int): Number of additional attempts after the first failure
631631
for each probe. Only exceptions/timeouts are retried; an explicit
632632
error response is final. Set to ``0`` to disable retries.
@@ -685,7 +685,7 @@ async def discover_target_capabilities_async(
685685
"""
686686
Probe both the boolean capability flags and the input modality combinations
687687
that ``target`` accepts, and return a merged best-effort
688-
:class:`TargetCapabilities`.
688+
``TargetCapabilities``.
689689
690690
Boolean capabilities with a registered probe are checked with live
691691
requests; capabilities without a probe fall back to the target's
@@ -704,17 +704,17 @@ async def discover_target_capabilities_async(
704704
the target's declared support.
705705
test_assets (dict[PromptDataType, str] | None): Mapping from non-text
706706
modality to a file path used as the probe payload. Defaults to
707-
:data:`DEFAULT_TEST_ASSETS`. Combinations whose non-text assets
707+
``DEFAULT_TEST_ASSETS``. Combinations whose non-text assets
708708
are missing on disk are skipped.
709709
capabilities (Iterable[CapabilityName] | None): Capabilities to probe.
710-
Defaults to every member of :class:`CapabilityName`. Capabilities
710+
Defaults to every member of ``CapabilityName``. Capabilities
711711
not listed here fall back to the target's declared support.
712712
retries (int): Number of additional attempts after the first failure
713713
for each probe. Only exceptions/timeouts are retried; an explicit
714714
error response is final. Set to ``0`` to disable retries.
715715
Defaults to 1.
716716
apply (bool): If True, install the discovered capabilities on ``target``
717-
via :meth:`PromptTarget.apply_capabilities` before returning.
717+
via ``PromptTarget.apply_capabilities`` before returning.
718718
Probe results are an upper bound (the request was accepted, not
719719
necessarily honored), so leave this False when you want to inspect
720720
or diff the result before committing to it. Defaults to False.
@@ -790,7 +790,7 @@ def _create_test_message(
790790
test_assets: dict[PromptDataType, str],
791791
) -> Message:
792792
"""
793-
Build a minimal :class:`Message` that exercises ``modalities``.
793+
Build a minimal ``Message`` that exercises ``modalities``.
794794
795795
Args:
796796
modalities (frozenset[PromptDataType]): The modalities to include.

pyrit/prompt_target/common/prompt_chat_target.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class PromptChatTarget(PromptTarget):
1313
"""
1414
.. deprecated:: 0.14.0
1515
``PromptChatTarget`` is deprecated and will be removed in v0.16.0. Use
16-
:class:`PromptTarget` directly with a ``TargetConfiguration`` declaring
16+
``PromptTarget`` directly with a ``TargetConfiguration`` declaring
1717
``supports_multi_turn=True`` and ``supports_editable_history=True``.
1818
19-
Backwards-compatible alias for :class:`PromptTarget`. All chat-target functionality
20-
(``set_system_prompt``, ``is_response_format_json``) lives on :class:`PromptTarget`.
21-
Subclassing or instantiating this class emits a :class:`DeprecationWarning`.
19+
Backwards-compatible alias for ``PromptTarget``. All chat-target functionality
20+
(``set_system_prompt``, ``is_response_format_json``) lives on ``PromptTarget``.
21+
Subclassing or instantiating this class emits a ``DeprecationWarning``.
2222
"""
2323

2424
_DEFAULT_CONFIGURATION: TargetConfiguration = TargetConfiguration(

pyrit/prompt_target/common/prompt_target.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ async def send_prompt_async(self, *, message: Message) -> list[Message]:
9494
1. Validates the message, fetches the conversation from memory, appends ``message``, and runs
9595
the normalization pipeline (system‑squash, history‑squash, etc.).
9696
2. Validates the normalized conversation against the target's capabilities.
97-
3. Delegates to :meth:`_send_prompt_to_target_async` with the normalized
97+
3. Delegates to ``_send_prompt_to_target_async`` with the normalized
9898
conversation.
9999
100100
Subclasses MUST NOT override this method. Override
101-
:meth:`_send_prompt_to_target_async` instead.
101+
``_send_prompt_to_target_async`` instead.
102102
103103
Args:
104104
message (Message): The message to send.
@@ -121,7 +121,7 @@ async def _send_prompt_to_target_async(self, *, normalized_conversation: list[Me
121121
"""
122122
Target-specific send logic.
123123
124-
Called by :meth:`send_prompt_async` after validation and normalization.
124+
Called by ``send_prompt_async`` after validation and normalization.
125125
126126
Args:
127127
normalized_conversation (list[Message]): The full conversation
@@ -263,7 +263,7 @@ def set_system_prompt(
263263
264264
If the target does not natively support system prompts, whether this
265265
call is ultimately honored depends on the target's
266-
:class:`CapabilityHandlingPolicy`:
266+
``CapabilityHandlingPolicy``:
267267
268268
* ``ADAPT`` — the normalization pipeline (e.g. system squash) will
269269
fold the system message into user content on the wire.
@@ -388,7 +388,7 @@ def apply_capabilities(self, *, capabilities: TargetCapabilities) -> None:
388388
389389
Policy is preserved because it expresses user intent (ADAPT vs RAISE),
390390
independent of what the probe found. To change policy or normalizer
391-
overrides, build a new :class:`TargetConfiguration` and pass it via
391+
overrides, build a new ``TargetConfiguration`` and pass it via
392392
``custom_configuration`` at construction time instead.
393393
394394
Note:

0 commit comments

Comments
 (0)