Skip to content

Commit 95985e3

Browse files
committed
Compatibility: pycode parser: adjust dedent-token handling for py3.12+
Refs: #11436
1 parent d3c91f9 commit 95985e3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sphinx/pycode/parser.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import inspect
77
import itertools
88
import re
9+
import sys
910
import tokenize
1011
from inspect import Signature
1112
from token import DEDENT, INDENT, NAME, NEWLINE, NUMBER, OP, STRING
@@ -525,7 +526,16 @@ def finalize_block(self) -> None:
525526
definition = self.indents.pop()
526527
if definition[0] != 'other':
527528
typ, funcname, start_pos = definition
528-
end_pos = self.current.end[0] - 1
529+
end_pos = self.current.end[0]
530+
531+
# The dedent end position on py3.12 is capped to the file linecount
532+
# refs: https://github.com/sphinx-doc/sphinx/issues/11436
533+
if sys.version_info[:2] >= (3, 12) and end_pos == len(self.buffers):
534+
pass
535+
else:
536+
end_pos -= 1
537+
538+
# Omit empty dedenting lines from the definition's location
529539
while emptyline_re.match(self.get_line(end_pos)):
530540
end_pos -= 1
531541

0 commit comments

Comments
 (0)