From 796eae3c46b142d479071fdf39f2e47f627da29e Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 8 Dec 2023 07:05:58 -0500 Subject: [PATCH] [pointless-string-statement] Ignore docstrings on py3.12 type aliases (#9269) --- doc/data/messages/p/pointless-string-statement/related.rst | 1 + doc/whatsnew/fragments/9268.false_positive | 4 ++++ pylint/checkers/base/basic_checker.py | 4 +++- tests/functional/s/statement_without_effect_py312.py | 7 +++++++ tests/functional/s/statement_without_effect_py312.rc | 2 ++ 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 doc/data/messages/p/pointless-string-statement/related.rst create mode 100644 doc/whatsnew/fragments/9268.false_positive create mode 100644 tests/functional/s/statement_without_effect_py312.py create mode 100644 tests/functional/s/statement_without_effect_py312.rc diff --git a/doc/data/messages/p/pointless-string-statement/related.rst b/doc/data/messages/p/pointless-string-statement/related.rst new file mode 100644 index 0000000000..b03ae2cd9b --- /dev/null +++ b/doc/data/messages/p/pointless-string-statement/related.rst @@ -0,0 +1 @@ +- `Discussion thread re: docstrings on assignments `_ diff --git a/doc/whatsnew/fragments/9268.false_positive b/doc/whatsnew/fragments/9268.false_positive new file mode 100644 index 0000000000..f360ea204e --- /dev/null +++ b/doc/whatsnew/fragments/9268.false_positive @@ -0,0 +1,4 @@ +Fixed ``pointless-string-statement`` false positive for docstrings +on Python 3.12 type aliases. + +Closes #9268 diff --git a/pylint/checkers/base/basic_checker.py b/pylint/checkers/base/basic_checker.py index 0bfbcece98..bd31905282 100644 --- a/pylint/checkers/base/basic_checker.py +++ b/pylint/checkers/base/basic_checker.py @@ -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) diff --git a/tests/functional/s/statement_without_effect_py312.py b/tests/functional/s/statement_without_effect_py312.py new file mode 100644 index 0000000000..5ea5d17e7b --- /dev/null +++ b/tests/functional/s/statement_without_effect_py312.py @@ -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) +""" diff --git a/tests/functional/s/statement_without_effect_py312.rc b/tests/functional/s/statement_without_effect_py312.rc new file mode 100644 index 0000000000..9c966d4bda --- /dev/null +++ b/tests/functional/s/statement_without_effect_py312.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.12