Skip to content

Commit e804089

Browse files
authored
[bc-lint] preserve source location info for async functions (#7158)
Fixes errors like: ``` File "/home/runner/work/vllm/vllm/_repo/../_test-infra/tools/stronghold/bin/check-api-compatibility/api/ast.py", line 90, in _function_def_to_parameters return tuple(map(_convert, node.elts)) ^^^^^^^^^^^ AttributeError: 'FunctionDef' object has no attribute 'lineno' ``` https://github.com/vllm-project/vllm/actions/runs/17661069007/job/50194417224?pr=24219 ### Testing unit-tests
1 parent c382fd8 commit e804089

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

tools/stronghold/src/api/ast.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:
211211
returns=node.returns,
212212
type_comment=node.type_comment,
213213
)
214+
# Preserve source location info (lineno/col_offset)
215+
fnode = ast.copy_location(fnode, node)
216+
ast.fix_missing_locations(fnode)
214217
self._functions[name] = fnode
215218

216219

tools/stronghold/tests/api/test_ast.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,38 @@ def func(self, /) -> None:
213213
}
214214

215215

216+
def test_extract_async_function(tmp_path: pathlib.Path) -> None:
217+
async def func(a: int, *, b: int = 0) -> None:
218+
pass # pragma: no cover
219+
220+
funcs = api.ast.extract(source.make_file(tmp_path, func)).functions
221+
assert funcs == {
222+
"func": api.Parameters(
223+
parameters=[
224+
api.Parameter(
225+
name="a",
226+
positional=True,
227+
keyword=True,
228+
required=True,
229+
line=1,
230+
type_annotation=api.types.TypeName("int"),
231+
),
232+
api.Parameter(
233+
name="b",
234+
positional=False,
235+
keyword=True,
236+
required=False,
237+
line=1,
238+
type_annotation=api.types.TypeName("int"),
239+
),
240+
],
241+
variadic_args=False,
242+
variadic_kwargs=False,
243+
line=1,
244+
)
245+
}
246+
247+
216248
def test_extract_dataclass(tmp_path: pathlib.Path) -> None:
217249
@dataclasses.dataclass
218250
class Class:

0 commit comments

Comments
 (0)