Skip to content

elt in generator expressions have incorrect type annotations #500

@zsol

Description

@zsol

The fine docs say that elt in the various comprehension nodes are of type BaseAssignTargetExpression. This is a lie. Observe: in the syntactically correct and semantically plausible expression (i ** 2 for i in _), the elt is constructed from i**2 which is a BinaryOperation:

> echo "(i**2 for _ in _)" | python -m libcst.tool print -
Module(
  body=[
    SimpleStatementLine(
      body=[
        Expr(
          value=GeneratorExp(
            elt=BinaryOperation(
              left=Name(
                value='i',
              ),
              operator=Power(),
              right=Integer(
                value='2',
              ),
            ),
            for_in=CompFor(
              target=Name(
                value='i',
              ),
              iter=Name(
                value='_',
              ),
            ),
          ),
        ),
      ],
    ),
  ],
)

But alas, BinaryOperation is not a BaseAssignTargetExpression.

>>> issubclass(cst.BinaryOperation, cst.BaseAssignTargetExpression)
False

What is the correct type for elt here? BaseExpression?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomersparsingConverting source code into CST nodes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions