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.exprcan be eitherast.Nameor_ast.Subscript. Onlyast.Namehas anidattribute.To use only
ast.Names use the following code: