ruff/crates
Dhruv Manilawala f79c980e17
Add support for attribute docstring in the semantic model (#11315)
## Summary

This PR adds updates the semantic model to detect attribute docstring.

Refer to [PEP 258](https://peps.python.org/pep-0258/#attribute-docstrings) 
for the definition of an attribute docstring.

This PR doesn't add full support for it but only considers string
literals as attribute docstring for the following cases:
1. A string literal following an assignment statement in the **global
scope**.
2. A global class attribute

For an assignment statement, it's considered an attribute docstring only
if the target expression is a name expression (`x = 1`). So, chained
assignment, multiple assignment or unpacking, and starred expression,
which are all valid in the target position, aren't considered here.

In `__init__` method, an assignment to the `self` variable like `self.x = 1`
is also a candidate for an attribute docstring. **This PR does not
support this position.**

## Test Plan

I used the following source code along with a print statement to verify
that the attribute docstring detection is correct.

Refer to the PR description for the code snippet.

I'll add this in the follow-up PR
(https://github.com/astral-sh/ruff/pull/11302) which uses this method.
2024-05-10 20:27:56 +05:30
..
red_knot [red-knot] @override lint rule (#11282) 2024-05-09 09:25:08 -06:00
ruff Bump version to v0.4.4 (#11352) 2024-05-09 17:00:46 +00:00
ruff_benchmark Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_cache Kick off Red-knot (#10849) 2024-04-27 08:34:00 +00:00
ruff_dev Docs: Link inline settings when not part of options section (#10499) 2024-03-21 16:33:58 +00:00
ruff_diagnostics Respect `# noqa` directives on `__all__` openers (#10798) 2024-04-06 14:51:17 +00:00
ruff_formatter Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
ruff_index Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_linter Add support for attribute docstring in the semantic model (#11315) 2024-05-10 20:27:56 +05:30
ruff_macros Fix comment copy/paste typo in newtype_index (#10892) 2024-04-11 18:43:52 -06:00
ruff_notebook Remove unused dependencies (#10475) 2024-03-19 17:33:47 +01:00
ruff_python_ast Use `u64` instead of `i64` in Int type (#11356) 2024-05-10 13:35:15 +00:00
ruff_python_ast_integration_tests Remove cyclic dev dependency with the parser crate (#11261) 2024-05-07 09:24:57 +00:00
ruff_python_codegen Refactor the `ExprDict` node (#11267) 2024-05-07 11:46:10 +00:00
ruff_python_formatter Refactor the `ExprDict` node (#11267) 2024-05-07 11:46:10 +00:00
ruff_python_index Fix Indexer fails to identify continuation preceded by newline #10351 (#10354) 2024-03-12 00:35:41 -04:00
ruff_python_literal Remove unused dependencies (#10475) 2024-03-19 17:33:47 +01:00
ruff_python_parser Use `u64` instead of `i64` in Int type (#11356) 2024-05-10 13:35:15 +00:00
ruff_python_resolver chore(deps): update rust crate insta to v1.38.0 (#10701) 2024-04-01 15:44:30 +00:00
ruff_python_semantic Add support for attribute docstring in the semantic model (#11315) 2024-05-10 20:27:56 +05:30
ruff_python_stdlib Improve handling of builtin symbols in linter rules (#10919) 2024-04-16 11:37:31 +01:00
ruff_python_trivia Remove cyclic dev dependency with the parser crate (#11261) 2024-05-07 09:24:57 +00:00
ruff_python_trivia_integration_tests Remove cyclic dev dependency with the parser crate (#11261) 2024-05-07 09:24:57 +00:00
ruff_server Touch-up error messages in server file discovery (#11285) 2024-05-05 13:20:51 -04:00
ruff_source_file Remove cyclic dev dependency with the parser crate (#11261) 2024-05-07 09:24:57 +00:00
ruff_text_size Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
ruff_wasm Remove ImportMap (#11234) 2024-05-02 11:26:02 -07:00
ruff_workspace Add globbing to isort sections docs (#11311) 2024-05-06 18:12:29 +00:00