Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Conversation

@bm-w
Copy link

@bm-w bm-w commented Apr 2, 2025

Python supports keyword arguments in its superclasses: (argument_list …), which somehow modify the superclass. The stanza capturing superclasses was erroneously capturing these keyword arguments as superclasses themselves as well, which would then cause an error upon emitting the edge:

0: Error executing statement edge @class.super_scope -> @superclass.output at (938, 3)
    src/stack-graphs.tsg:938:3:
    938 |   edge @class.super_scope -> @superclass.output
        |   ^
    in stanza
    src/stack-graphs.tsg:934:1:
    934 | (class_definition
        | ^
    matching (class_definition) node
    test/superclasses.py:11:1:
    11 | class B(A, foo="Bar"):
        | ^
1: Evaluating edge sink
2: Undefined scoped variable [syntax node keyword_argument (11, 12)].output

The fragment of the parsed Tree-sitter tree for such a superclass argument list with keyword arguments is:

superclasses: (argument_list
  (identifier)
  (keyword_argument …))

As of v0.23.5 of the Python grammar, the superclasses field is indeed an argument_list syntax node, which in turn can contain either an expression or a keyword_argument (among other things), and expression in turn can be a whole host of types of syntax nodes.

Explicitly capturing only identifier and attribute (which are dotted identifier chains like foo.bar) syntax nodes fixes the issue. This is possibly too strict, since technically any expression can be used here, but it likely captures the vast majority of cases out there.

Copilot AI review requested due to automatic review settings April 2, 2025 01:06
@bm-w bm-w requested review from a team as code owners April 2, 2025 01:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue with how Python superclass keyword arguments are handled by updating the captured nodes to only include valid superclass expressions.

  • Updated test file to include a subclass with a keyword argument in its superclass list.
  • Adjusted inline comments to reflect the updated definition line numbers.
Files not reviewed (1)
  • languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg: Language not supported

@CleanCut
Copy link
Contributor

CleanCut commented Sep 9, 2025

The github/stack-graphs repository is no longer being maintained. As per #502, I'm closing all issues and pull requests before archiving the repository.

@CleanCut CleanCut closed this Sep 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants