From 72a3accbf4101beb11347b90860f4f114ee6cd36 Mon Sep 17 00:00:00 2001 From: Alfred Wingate Date: Wed, 1 Nov 2023 11:12:08 +0200 Subject: [PATCH] Add support for PEP701 * fstring don't emit tk.STRING in python3.12, reattach the now separate tokens and pass them to Docstring preserving previous behavior. Closes: https://github.com/PyCQA/pydocstyle/issues/646 Signed-off-by: Alfred Wingate --- docs/release_notes.rst | 8 ++++++++ src/pydocstyle/parser.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 46e3656..3db4c18 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -4,6 +4,14 @@ Release Notes **pydocstyle** version numbers follow the `Semantic Versioning `_ specification. + +Current development version +--------------------------- + +Bug Fixes + +* Add support for PEP-701 fixing fstring parsing in python3.12 (#656). + 6.3.0 - January 17th, 2023 -------------------------- diff --git a/src/pydocstyle/parser.py b/src/pydocstyle/parser.py index 95bd0a1..77e665b 100644 --- a/src/pydocstyle/parser.py +++ b/src/pydocstyle/parser.py @@ -479,6 +479,20 @@ def parse_docstring(self): ) self.stream.move() return docstring + if (sys.version_info.major, sys.version_info.minor) >= ( + 3, + 12, + ) and self.current.kind == tk.FSTRING_START: + # Reattach fstring tokens together to deal with PEP 701 in python3.12 + value = self.current.value + start = self.current.start[0] + while self.current.kind != tk.FSTRING_END: + self.stream.move() + value += self.current.value + end = self.current.end[0] + docstring = Docstring(value, start, end) + self.stream.move() + return docstring return None def parse_decorators(self):