Skip to content

[Question] Is there an API to annotate the ast #4713

Closed
@sk-

Description

@sk-

Is there an api to annotate the AST, I'm interested in knowing the type of all subexpressions.

For example in the code:

min(3, 4)
'foo' * 2
def f(a: int, min: Callable[[int, int], int]) -> int:
  return min(a, 314)

I would like to know that

min -> __builtin__.min
3 -> int
4 -> int
min(3, 4) -> int
'foo' -> str
2 -> int
'foo' * 2 -> str

# In function f
a -> int
314 int
min -> Callable[[int, int], int] not __builtin__.min
min(a, 314) -> int

and ideally the expression should have line number and offset information to match it with the AST nodes.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions