Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ def flexible(*args, **kwargs):
parser.delete();
});

it("extracts type-annotated *args and **kwargs", () => {
const { tree, parser, root } = parse(`
def f(a: int, *args: str, b: int = 0, **kwargs: bool):
pass
`);
const result = extractor.extractStructure(root);

expect(result.functions[0].params).toEqual([
"a",
"*args",
"b",
"**kwargs",
]);

tree.delete();
parser.delete();
});

it("extracts decorated functions", () => {
const { tree, parser, root } = parse(`
@decorator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ function extractParams(paramsNode: TreeSitterNode | null): string[] {
break;

case "typed_parameter": {
const splat = findChild(child, "list_splat_pattern");
if (splat) {
const sid = findChild(splat, "identifier");
if (sid) params.push("*" + sid.text);
break;
}
const dsplat = findChild(child, "dictionary_splat_pattern");
if (dsplat) {
const did = findChild(dsplat, "identifier");
if (did) params.push("**" + did.text);
break;
}
const ident = findChild(child, "identifier");
if (ident && ident.text !== "self" && ident.text !== "cls") {
params.push(ident.text);
Expand Down
Loading