Code:
def extract_assignment(assignment: ast.Assign) -> Dict[str, LINES_RANGE]:
targets = ', '.join(t.id for t in assignment.targets)
pyright/mypy:
error: "expr" has no attribute "id"
From typeshed:
class Assign(stmt):
targets: typing.List[expr]
value: expr
Consider the following Code:
Running the following ast inspection:
prints the following:
So in this case
ast.expr
can be eitherast.Name
or_ast.Subscript
. Onlyast.Name
has anid
attribute.To use only
ast.Name
s use the following code: