This repository was archived by the owner on Sep 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +52
-12
lines changed
languages/tree-sitter-stack-graphs-python Expand file tree Collapse file tree 4 files changed +52
-12
lines changed Original file line number Diff line number Diff line change 1+ (class_definition
2+ body: (
3+ block
4+ (function_definition
5+ parameters:
6+ (parameters
7+ . (identifier) @first_param
8+ )
9+ body: (block) @method_body
10+ )
11+ )
12+ )
Original file line number Diff line number Diff line change @@ -794,19 +794,29 @@ inherit .parent_module
794794 edge @name.def -> @func.call
795795
796796 ; Prevent functions defined inside of method bodies from being treated like methods
797+ ; There might be a bug here as calling .self_scope after this, will not fallback to the larger scope
797798 let @body.class_self_scope = #null
798799 let @body.class_member_attr_scope = #null
799800}
800801
801- (function_definition
802- parameters: (parameters
803- . (identifier) @param)
804- body: (block) @body)
802+ ; method definition
803+ (class_definition
804+ body: (
805+ block
806+ (function_definition
807+ parameters:
808+ (parameters
809+ . (identifier) @first_param
810+ )
811+ body: (block) @method_body
812+ )
813+ )
814+ )
805815{
806- edge @param .def -> @param .class_self_scope
807- edge @param .class_member_attr_scope -> @param .output
808- edge @param .output -> @body .after_scope
809- attr (@param .output) push_node = @param
816+ edge @first_param .def -> @first_param .class_self_scope
817+ edge @first_param .class_member_attr_scope -> @first_param .output
818+ edge @first_param .output -> @method_body .after_scope
819+ attr (@first_param .output) push_node = @first_param
810820}
811821
812822[
Original file line number Diff line number Diff line change 11class Foo :
22 a = 1
33
4- # Self can be named anything
5- def first_method (actually_self ):
6- return actually_self .a
7- # ^ defined: 2
4+ def first_method (self ):
5+ self .a
6+ # ^ defined: 2
87
98 def second_method (self ):
9+ self .a
10+ # ^ defined: 2
11+
1012 # First argument here is not self
1113 def not_a_method (not_self ):
1214 return not_self .a
1315 # ^ defined:
16+
17+
18+ def function (self ):
19+ self .a
20+ # ^ defined:
Original file line number Diff line number Diff line change 1+ class Foo :
2+ a = 1
3+
4+ def mathod_1 (self ):
5+ return self .a
6+ # ^ defined: 2
7+
8+ # Self can be named anything
9+ def method_2 (actually_self ):
10+ return actually_self .a
11+ # ^ defined: 2
You can’t perform that action at this time.
0 commit comments