ruff/crates/ruff_python_semantic/src
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
..
analyze [flake8-pyi] Implement PYI062 (duplicate-literal-member) (#11269) 2024-05-07 19:28:06 +01:00
model Improve ruff_python_semantic::all::extract_all_names() (#11335) 2024-05-08 17:09:31 +01:00
binding.rs Move all module from the AST to the semantic crate (#11330) 2024-05-08 08:56:50 +00:00
branches.rs Add branch detection to the semantic model (#6694) 2023-08-19 21:28:17 +00:00
context.rs Remove separate ReferenceContext enum (#4631) 2023-05-24 15:12:38 +00:00
definition.rs Improve ruff_python_semantic::all::extract_all_names() (#11335) 2024-05-08 17:09:31 +01:00
globals.rs Refine SemanticModel lifetime bounds (#10221) 2024-03-04 09:21:13 +01:00
lib.rs Improve ruff_python_semantic::all::extract_all_names() (#11335) 2024-05-08 17:09:31 +01:00
model.rs Add support for attribute docstring in the semantic model (#11315) 2024-05-10 20:27:56 +05:30
nodes.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
reference.rs Correctly handle references in __all__ definitions when renaming symbols in autofixes (#10527) 2024-03-22 20:06:35 +00:00
scope.rs Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
star_import.rs Make ImportFrom level just a u32 (#11170) 2024-04-26 20:38:35 -06:00