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 Nov 28, 2023
1 parent 37081fd commit ae7383a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
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 ae7383a

Please sign in to comment.