Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport maintenance/3.0.x] [pointless-string-statement] Ignore docstrings on py3.12 type aliases #9287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/data/messages/p/pointless-string-statement/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `Discussion thread re: docstrings on assignments <https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816>`_
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/9268.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixed ``pointless-string-statement`` false positive for docstrings
on Python 3.12 type aliases.

Closes #9268
4 changes: 3 additions & 1 deletion pylint/checkers/base/basic_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ def visit_expr(self, node: nodes.Expr) -> None:
if (
sibling is not None
and sibling.scope() is scope
and isinstance(sibling, (nodes.Assign, nodes.AnnAssign))
and isinstance(
sibling, (nodes.Assign, nodes.AnnAssign, nodes.TypeAlias)
)
):
return
self.add_message("pointless-string-statement", node=node)
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/s/statement_without_effect_py312.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Move this into statement_without_effect.py when python 3.12 is minimum."""

type MyTuple = tuple[str, str]
"""
Multiline docstring
for Python3.12 type alias (PEP 695)
"""
2 changes: 2 additions & 0 deletions tests/functional/s/statement_without_effect_py312.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.12