Skip to content

Commit e969a9c

Browse files
committed
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: PyCQA#646 Signed-off-by: Alfred Wingate <[email protected]>
1 parent 6d5455e commit e969a9c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/pydocstyle/parser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,20 @@ def parse_docstring(self):
479479
)
480480
self.stream.move()
481481
return docstring
482+
if (sys.version_info.major, sys.version_info.minor) >= (
483+
3,
484+
12,
485+
) and self.current.kind == tk.FSTRING_START:
486+
# Reattach fstring tokens together to deal with PEP 701 in python3.12
487+
value = self.current.value
488+
start = self.current.start[0]
489+
while self.current.kind != tk.FSTRING_END:
490+
self.stream.move()
491+
value += self.current.value
492+
end = self.current.end[0]
493+
docstring = Docstring(value, start, end)
494+
self.stream.move()
495+
return docstring
482496
return None
483497

484498
def parse_decorators(self):

0 commit comments

Comments
 (0)