Skip to content

Commit

Permalink
[pointless-string-statement] Ignore docstrings on py3.12 type aliases (
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Dec 8, 2023
1 parent db6dcfc commit 796eae3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
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

0 comments on commit 796eae3

Please sign in to comment.