Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Fix bug in handling of **kwargs in class bases #17809

Merged
merged 2 commits into from
Oct 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion python/extractor/tests/parser/class.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class Foo(int, object, metaclass=type):
class Foo(int, object, metaclass=type, **kwargs):
x = 5
17 changes: 14 additions & 3 deletions python/extractor/tsg-python/python.tsg
Original file line number Diff line number Diff line change
Expand Up @@ -1277,16 +1277,18 @@
attr (@class.inner_scope -> @stmt.node) body = (named-child-index @stmt)
}

; Class.bases - using `(_ !name)` as a proxy for all non-keyword arguments.
; Class.bases - using `(_ !value !name)` as a proxy for all non-keyword arguments.
; In particular, `keyword_argument` nodes have a `name` field, and `dictionary_splat`
; nodes have a `value` field.
(class_definition
superclasses: (argument_list element: (_ !name) @arg)
superclasses: (argument_list element: (_ !value !name) @arg)
) @class
{
edge @class.class_expr -> @arg.node
attr (@class.class_expr -> @arg.node) bases = (named-child-index @arg)
}

; Class.keywords
; Class.keywords of the form `foo=bar`
(class_definition
superclasses: (argument_list element: (keyword_argument) @arg)
) @class
Expand All @@ -1295,6 +1297,15 @@
attr (@class.class_expr -> @arg.node) keywords = (named-child-index @arg)
}

; Class.keywords of the form `**kwargs`
(class_definition
superclasses: (argument_list element: (dictionary_splat) @arg)
) @class
{
edge @class.class_expr -> @arg.node
attr (@class.class_expr -> @arg.node) keywords = (named-child-index @arg)
}

;;;;;; End of Class

;;;;;; Assign statements
Expand Down
Loading