Skip to content

Commit

Permalink
fix: Fix iterating non-flat expressions (some nodes were skipped)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Sep 4, 2023
1 parent 3821ccd commit 3249155
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/griffe/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class ExprCall(Expr):
arguments: Sequence[str | Expr]

def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: D102
yield from self.function.iterate(flat=flat)
yield from _yield(self.function, flat=flat)
yield "("
yield from _join(self.arguments, ", ", flat=flat)
yield ")"
Expand Down Expand Up @@ -293,11 +293,12 @@ class ExprDict(Expr):
keys: Sequence[str | Expr | None]
values: Sequence[str | Expr]

def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: ARG002,D102
def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: D102
yield "{"
yield from _join(
(("None" if key is None else key, ": ", value) for key, value in zip(self.keys, self.values)),
", ",
flat=flat,
)
yield "}"

Expand Down Expand Up @@ -403,7 +404,7 @@ class ExprVarPositional(Expr):

def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: D102
yield "*"
yield from self.value.iterate(flat=flat)
yield from _yield(self.value, flat=flat)


@dataclass(eq=True, **dataclass_opts)
Expand All @@ -414,7 +415,7 @@ class ExprVarKeyword(Expr):

def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: D102
yield "**"
yield from self.value.iterate(flat=flat)
yield from _yield(self.value, flat=flat)


@dataclass(eq=True, **dataclass_opts)
Expand Down Expand Up @@ -520,7 +521,7 @@ class ExprNamedExpr(Expr):

def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: D102
yield "("
yield from self.target.iterate(flat=flat)
yield from _yield(self.target, flat=flat)
yield " := "
yield from _yield(self.value, flat=flat)
yield ")"
Expand Down Expand Up @@ -590,7 +591,7 @@ class ExprSubscript(Expr):
slice: Expr # noqa: A003

def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: D102
yield from self.left.iterate(flat=flat)
yield from _yield(self.left, flat=flat)
yield "["
yield from _yield(self.slice, flat=flat)
yield "]"
Expand Down

0 comments on commit 3249155

Please sign in to comment.