mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
![]() ## 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. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |