Skip to content

Commit 721918a

Browse files
committed
fixing argument offset logic
1 parent 0beeb33 commit 721918a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

devtools/debug.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ def _process_args(self, func_ast, code_lines, args, kwargs) -> Generator[DebugAr
125125
yield self.output_class.arg_class(arg, name=ast_node.id)
126126
elif isinstance(ast_node, self.complex_nodes):
127127
# TODO replace this hack with astor when it get's round to a new release
128-
start_line, start_col = ast_node.lineno - 1, ast_node.col_offset
129-
end_line, end_col = len(code_lines) - 1, None
128+
start_line, start_col = arg_offsets[i]
130129

131-
if i < len(arg_offsets) - 1:
130+
if i + 1 < len(arg_offsets):
132131
end_line, end_col = arg_offsets[i + 1]
132+
else:
133+
end_line, end_col = len(code_lines) - 1, None
133134

134135
name_lines = []
135136
for l in range(start_line, end_line + 1):
@@ -193,7 +194,12 @@ def _parse_code(self, call_frame, func_regex, filename) -> Tuple[Optional[ast.AS
193194
@classmethod
194195
def _get_offsets(cls, func_ast):
195196
for arg in func_ast.args:
196-
yield arg.lineno - 1, arg.col_offset
197+
start_line, start_col = arg.lineno - 1, arg.col_offset
198+
199+
# horrible hack for http://bugs.python.org/issue31241
200+
if isinstance(arg, (ast.ListComp, ast.GeneratorExp)):
201+
start_col -= 1
202+
yield start_line, start_col
197203
for kw in func_ast.keywords:
198204
yield kw.value.lineno - 1, kw.value.col_offset - len(kw.arg) - 1
199205

tests/test_expr_render.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def test_exotic_types():
4545
' 1 < 2 = True (bool)\n'
4646
' 1 << 2 = 4 (int)\n'
4747
' \'t\' if True else \'f\' = "t" (str) len=1\n'
48-
' 1 or 2, [ = 1 (int)\n'
49-
' a for a in aa] = [1, 2, 3] (list)\n'
48+
' 1 or 2 = 1 (int)\n'
49+
' [a for a in aa] = [1, 2, 3] (list)\n'
5050
' {a for a in aa} = {1, 2, 3} (set)\n'
51-
' {a: a + 1 for a in aa}, ( = {1: 2, 2: 3, 3: 4} (dict)\n'
52-
' a for a in aa) = <generator object test_exotic_types.<locals>.<genexpr> at 0x<hash>> (generator)'
51+
' {a: a + 1 for a in aa} = {1: 2, 2: 3, 3: 4} (dict)\n'
52+
' (a for a in aa) = <generator object test_exotic_types.<locals>.<genexpr> at 0x<hash>> (generator)'
5353
) == s
5454

5555

0 commit comments

Comments
 (0)