Skip to content
This repository was archived by the owner on Jan 3, 2026. It is now read-only.

Commit 4b46909

Browse files
author
whitequark
committed
Do not consider commented-out lines when calculating indentation level.
1 parent 58a0c8f commit 4b46909

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

pythonparser/lexer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def _refill(self, eof_token):
260260

261261
# Should we emit indent/dedent?
262262
if self.new_line and \
263-
match.group(3) is None: # not a blank line
263+
match.group(3) is None and \
264+
match.group(4) is None: # not a blank line
264265
whitespace = match.string[match.start(0):match.start(1)]
265266
level = len(whitespace.expandtabs())
266267
range = source.Range(self.source_buffer, match.start(1), match.start(1))

pythonparser/test/test_lexer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def test_comment(self):
7777
"pass", None,
7878
"dedent", None)
7979

80+
self.assertLexes("class x:\n # foo\n pass",
81+
"class", None,
82+
"ident", "x",
83+
":", None,
84+
"newline", None,
85+
"indent", None,
86+
"pass", None,
87+
"dedent", None)
88+
8089
def test_float(self):
8190
self.assertLexes("0.0",
8291
"float", 0.0)

0 commit comments

Comments
 (0)