Skip to content

Inspect the AST instead of iterating through the tokenized source #22

@cknd

Description

@cknd

Currently, to find out where in the code which variable names occur, I traverse the code token-by-token and apply a sort of ad hoc stack machine that detects stuff like the beginning of function definitions, dot attributes etc. This is clearly nuts, and purely a path effect (= it's how ipython's ultratb does it, and then my scope expanded and here we are).
https://github.com/cknd/stackprinter/blob/master/stackprinter/source_inspection.py

This approach works for now, but it has hit its limits. For example, I'd like to ignore the left-hand side of named arguments in function calls.

Goals:

  • annotate in a piece of code where each variable name occurs, exactly like the current system, but with less of a home made rube goldberg machine behind it.
  • keep the ability to rerender the original code character by character as it appears in the source file (incl extra whitespaces, comment ascii art etc -- so people can visually recognize their code)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions