ruff/crates
GiGaGon 8f400bb37a
[pydoclint] Make example error out-of-the-box (DOC501) (#19218)
<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

Part of #18972

This PR makes [docstring-missing-exception
(DOC501)](https://docs.astral.sh/ruff/rules/docstring-missing-exception/#docstring-missing-exception-doc501)'s
example error out-of-the-box. Since the exceptions in the function body
need to undergo name resolution to figure out if one of them is
`NotImplementedError`, `DOC501` won't lint if the raised name is not
defined. This could be considered a limitation, but should be fine since
`F821` already covers undefined names. I did discover a different edge
case, but it's not relevant to the example.

[Old example](https://play.ruff.rs/d213e87d-e5c7-49d8-a908-931f61f06055)
```py
def calculate_speed(distance: float, time: float) -> float:
    """Calculate speed as distance divided by time.

    Args:
        distance: Distance traveled.
        time: Time spent traveling.

    Returns:
        Speed as distance divided by time.
    """
    try:
        return distance / time
    except ZeroDivisionError as exc:
        raise FasterThanLightError from exc
```

[New example](https://play.ruff.rs/cb41e0b7-b950-4fa0-842d-cecab9c8e842)
```py
class FasterThanLightError(ArithmeticError): ...


def calculate_speed(distance: float, time: float) -> float:
    """Calculate speed as distance divided by time.

    Args:
        distance: Distance traveled.
        time: Time spent traveling.

    Returns:
        Speed as distance divided by time.
    """
    try:
        return distance / time
    except ZeroDivisionError as exc:
        raise FasterThanLightError from exc
```

The "Use instead" section was also updated similarly.

## Test Plan

<!-- How was it tested? -->

N/A, no functionality/tests affected
2025-07-09 12:59:31 -04:00
..
ruff Rename Diagnostic::syntax_error methods, separate Ord implementation (#19179) 2025-07-08 09:54:19 -04:00
ruff_annotate_snippets Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
ruff_benchmark [ty] Re-enable multithreaded pydantic benchmark (#19176) 2025-07-07 14:28:15 +02:00
ruff_cache Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_db Auto-generate environment variable references for ty (#19205) 2025-07-08 10:48:31 -04:00
ruff_dev Auto-generate environment variable references for ty (#19205) 2025-07-08 10:48:31 -04:00
ruff_diagnostics Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_formatter Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_graph Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
ruff_index Update Rust toolchain to 1.88 and MSRV to 1.86 (#19011) 2025-06-28 20:24:00 +02:00
ruff_linter [pydoclint] Make example error out-of-the-box (DOC501) (#19218) 2025-07-09 12:59:31 -04:00
ruff_macros [ty] Merge ty_macros into ruff_macros (#19229) 2025-07-09 11:28:21 +00:00
ruff_notebook Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_options_metadata [ty] Document configuration schema (#17950) 2025-05-09 10:47:45 +02:00
ruff_python_ast Make dependency get-size2 truly optional in ruff_python_ast (#19052) 2025-06-30 21:50:59 -05:00
ruff_python_ast_integration_tests [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
ruff_python_codegen Fix f-string interpolation escaping (#18882) 2025-06-25 10:04:15 +02:00
ruff_python_formatter Update pre-commit dependencies (#19162) 2025-07-07 04:07:44 +00:00
ruff_python_index Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_literal Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_parser Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_python_semantic [flake8-pyi] Expand Optional[A] to A | None (PYI016) (#18572) 2025-06-27 15:43:11 +00:00
ruff_python_stdlib Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_trivia Treat ty: comments as pragma comments (#18532) 2025-06-07 16:02:43 +02:00
ruff_python_trivia_integration_tests Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_server Rename Diagnostic::syntax_error methods, separate Ord implementation (#19179) 2025-07-08 09:54:19 -04:00
ruff_source_file [ty] Add environment variable to dump Salsa memory usage stats (#18928) 2025-06-26 21:27:51 +00:00
ruff_text_size [ty] Add environment variable to dump Salsa memory usage stats (#18928) 2025-06-26 21:27:51 +00:00
ruff_wasm Combine OldDiagnostic and Diagnostic (#19053) 2025-07-03 13:01:09 -04:00
ruff_workspace Fix description of the format.skip-magic-trailing-comma example (#19095) 2025-07-03 10:39:59 -04:00
ty Auto-generate environment variable references for ty (#19205) 2025-07-08 10:48:31 -04:00
ty_ide [ty] Add type information to all_members API 2025-07-09 12:03:56 -04:00
ty_project [ty] Do not report settings diagnostics in check_file (#19206) 2025-07-08 10:18:32 -04:00
ty_python_semantic [ty] Add "kind" to completion suggestions 2025-07-09 12:03:56 -04:00
ty_server [ty] Add "kind" to completion suggestions 2025-07-09 12:03:56 -04:00
ty_static [ty] Merge ty_macros into ruff_macros (#19229) 2025-07-09 11:28:21 +00:00
ty_test Auto-generate environment variable references for ty (#19205) 2025-07-08 10:48:31 -04:00
ty_vendored [ty] Sync vendored typeshed stubs (#19174) 2025-07-07 12:00:09 +02:00
ty_wasm [ty] Support LSP go-to with vendored typeshed stubs (#19057) 2025-07-02 07:58:58 -04:00