Skip to content

Commit

Permalink
Compatibility: pycode parser: adjust dedent-token handling for py3.12+
Browse files Browse the repository at this point in the history
Refs: #11436
  • Loading branch information
jayaddison committed May 22, 2023
1 parent d3c91f9 commit 95985e3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sphinx/pycode/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import inspect
import itertools
import re
import sys
import tokenize
from inspect import Signature
from token import DEDENT, INDENT, NAME, NEWLINE, NUMBER, OP, STRING
Expand Down Expand Up @@ -525,7 +526,16 @@ def finalize_block(self) -> None:
definition = self.indents.pop()
if definition[0] != 'other':
typ, funcname, start_pos = definition
end_pos = self.current.end[0] - 1
end_pos = self.current.end[0]

# The dedent end position on py3.12 is capped to the file linecount
# refs: https://github.com/sphinx-doc/sphinx/issues/11436
if sys.version_info[:2] >= (3, 12) and end_pos == len(self.buffers):
pass
else:
end_pos -= 1

# Omit empty dedenting lines from the definition's location
while emptyline_re.match(self.get_line(end_pos)):
end_pos -= 1

Expand Down

0 comments on commit 95985e3

Please sign in to comment.