From d6047439ae4e9efc418269817c7c8047d2794b5a Mon Sep 17 00:00:00 2001 From: Bastiaan Marinus van de Weerd Date: Tue, 1 Apr 2025 21:52:53 -0300 Subject: [PATCH] Fix supercclass keyword arguments in Python. --- .../src/stack-graphs.tsg | 5 ++++- .../test/superclasses.py | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg b/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg index 5fb407ae8..2b06c1d2e 100644 --- a/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg +++ b/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg @@ -933,7 +933,10 @@ inherit .parent_module (class_definition superclasses: (argument_list - (_) @superclass)) @class + [ + (identifier) + (attribute) + ] @superclass)) @class { edge @class.super_scope -> @superclass.output } diff --git a/languages/tree-sitter-stack-graphs-python/test/superclasses.py b/languages/tree-sitter-stack-graphs-python/test/superclasses.py index 849a192a6..64ace2315 100644 --- a/languages/tree-sitter-stack-graphs-python/test/superclasses.py +++ b/languages/tree-sitter-stack-graphs-python/test/superclasses.py @@ -1,19 +1,22 @@ class A: + def __init_subclass__(cls, foo): + pass + def __init__(self): self.some_attr = 2 def some_method(self): print self -class B(A): +class B(A, foo="Bar"): def method2(self): print self.some_attr, self.some_method() - # ^ defined: 3 - # ^ defined: 5, 14 + # ^ defined: 6 + # ^ defined: 8, 17 def some_method(self): pass def other(self): super().some_method() - # ^ defined: 5 + # ^ defined: 8