Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return type to get_children #2094

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import typing
import warnings
from collections.abc import Generator, Iterable, Mapping
from collections.abc import Generator, Iterable, Iterator, Mapping
from functools import lru_cache
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, TypeVar, Union

Expand Down Expand Up @@ -346,7 +346,7 @@ def pytype(self) -> str:
:returns: The name of the type.
"""

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.elts


Expand Down Expand Up @@ -886,7 +886,7 @@ def find_argname(self, argname, rec=False):
return _find_arg(argname, self.arguments, rec)
return None, None

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.posonlyargs or ()

for elt in self.posonlyargs_annotations:
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def postinit(self, expr: NodeNG) -> None:
See astroid/protocols.py for actual implementation.
"""

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.expr


Expand Down Expand Up @@ -1075,7 +1075,7 @@ def postinit(self, test: NodeNG | None = None, fail: NodeNG | None = None) -> No
self.fail = fail
self.test = test

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.test

if self.fail is not None:
Expand Down Expand Up @@ -1121,7 +1121,7 @@ def postinit(
See astroid/protocols.py for actual implementation.
"""

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.targets

yield self.value
Expand Down Expand Up @@ -1177,7 +1177,7 @@ def postinit(
See astroid/protocols.py for actual implementation.
"""

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.target
yield self.annotation

Expand Down Expand Up @@ -1262,7 +1262,7 @@ def type_errors(self, context: InferenceContext | None = None):
except InferenceError:
return []

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.target
yield self.value

Expand Down Expand Up @@ -1339,7 +1339,7 @@ def type_errors(self, context: InferenceContext | None = None):
except InferenceError:
return []

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.left
yield self.right

Expand Down Expand Up @@ -1413,7 +1413,7 @@ def postinit(self, values: list[NodeNG] | None = None) -> None:
if values is not None:
self.values = values

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.values

def op_precedence(self):
Expand Down Expand Up @@ -1512,7 +1512,7 @@ def kwargs(self) -> list[Keyword]:
"""The keyword arguments that unpack something."""
return [keyword for keyword in self.keywords if keyword.arg is None]

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.func

yield from self.args
Expand Down Expand Up @@ -1545,7 +1545,7 @@ def postinit(self, left: NodeNG, ops: list[tuple[str, NodeNG]]) -> None:
self.left = left
self.ops = ops

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
"""Get the child nodes below this node.

Overridden to handle the tuple fields and skip returning the operator
Expand Down Expand Up @@ -1666,7 +1666,7 @@ def _get_filtered_stmts(

return stmts, False

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.target
yield self.iter

Expand Down Expand Up @@ -1911,7 +1911,7 @@ def scope(self) -> LocalsDictNodeNG:
raise ParentMissingError(target=self.parent)
return self.parent.parent.scope()

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.nodes


Expand Down Expand Up @@ -1956,7 +1956,7 @@ def __init__(
def postinit(self, expr: NodeNG) -> None:
self.expr = expr

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.expr


Expand Down Expand Up @@ -1996,7 +1996,7 @@ def __init__(
def postinit(self, targets: list[NodeNG]) -> None:
self.targets = targets

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.targets


Expand Down Expand Up @@ -2088,7 +2088,7 @@ def pytype(self) -> Literal["builtins.dict"]:
"""
return "builtins.dict"

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
"""Get the key and value nodes below this node.

Children are returned in the order that they are defined in the source
Expand Down Expand Up @@ -2220,7 +2220,7 @@ def postinit(self, value: NodeNG | None = None) -> None:
"""
self.value = value

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.value

def _get_yield_nodes_skip_lambdas(self):
Expand Down Expand Up @@ -2317,7 +2317,7 @@ def __init__(
See astroid/protocols.py for actual implementation.
"""

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
if self.type is not None:
yield self.type

Expand Down Expand Up @@ -2487,7 +2487,7 @@ def blockstart_tolineno(self):
"""
return self.iter.tolineno

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.target
yield self.iter

Expand Down Expand Up @@ -2574,7 +2574,7 @@ def postinit(self, value: NodeNG | None = None) -> None:
"""
self.value = value

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.value


Expand Down Expand Up @@ -2683,7 +2683,7 @@ def __init__(
def postinit(self, expr: NodeNG) -> None:
self.expr = expr

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.expr


Expand Down Expand Up @@ -2811,7 +2811,7 @@ def block_range(self, lineno: int) -> tuple[int, int]:
return lineno, self.body[-1].tolineno
return self._elsed_block_range(lineno, self.orelse, self.body[0].fromlineno - 1)

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.test

yield from self.body
Expand Down Expand Up @@ -2903,7 +2903,7 @@ def postinit(self, test: NodeNG, body: NodeNG, orelse: NodeNG) -> None:
self.body = body
self.orelse = orelse

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.test
yield self.body
yield self.orelse
Expand Down Expand Up @@ -3017,7 +3017,7 @@ def __init__(
def postinit(self, value: NodeNG) -> None:
self.value = value

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.value


Expand Down Expand Up @@ -3230,7 +3230,7 @@ def raises_not_implemented(self) -> bool:
name.name == "NotImplementedError" for name in self.exc._get_name_nodes()
)

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
if self.exc is not None:
yield self.exc

Expand Down Expand Up @@ -3289,7 +3289,7 @@ def postinit(self, value: NodeNG | None = None) -> None:
"""
self.value = value

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
if self.value is not None:
yield self.value

Expand Down Expand Up @@ -3430,7 +3430,7 @@ def igetattr(self, attrname, context: InferenceContext | None = None):
def getattr(self, attrname, context: InferenceContext | None = None):
return self._proxied.getattr(attrname, context)

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
if self.lower is not None:
yield self.lower

Expand Down Expand Up @@ -3485,7 +3485,7 @@ def postinit(self, value: NodeNG) -> None:
See astroid/protocols.py for actual implementation.
"""

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.value


Expand Down Expand Up @@ -3535,7 +3535,7 @@ def postinit(self, value: NodeNG, slice: NodeNG) -> None:
self.value = value
self.slice = slice

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.value
yield self.slice

Expand Down Expand Up @@ -3638,7 +3638,7 @@ def block_range(self, lineno: int) -> tuple[int, int]:
last = exhandler.body[0].fromlineno - 1
return self._elsed_block_range(lineno, self.orelse, last)

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.body

yield from self.handlers or ()
Expand Down Expand Up @@ -3734,7 +3734,7 @@ def block_range(self, lineno: int) -> tuple[int, int]:
return child.block_range(lineno)
return self._elsed_block_range(lineno, self.finalbody)

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.body
yield from self.finalbody

Expand Down Expand Up @@ -3833,7 +3833,7 @@ def block_range(self, lineno: int) -> tuple[int, int]:
return lineno, self.finalbody[-1].tolineno
return lineno, self.tolineno

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.body
yield from self.handlers
yield from self.orelse
Expand Down Expand Up @@ -3974,7 +3974,7 @@ def type_errors(self, context: InferenceContext | None = None):
except InferenceError:
return []

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.operand

def op_precedence(self):
Expand Down Expand Up @@ -4076,7 +4076,7 @@ def block_range(self, lineno: int) -> tuple[int, int]:
"""
return self._elsed_block_range(lineno, self.orelse)

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.test

yield from self.body
Expand Down Expand Up @@ -4179,7 +4179,7 @@ def blockstart_tolineno(self):
"""
return self.items[-1][0].tolineno

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
"""Get the child nodes below this node.

:returns: The children.
Expand Down Expand Up @@ -4247,7 +4247,7 @@ def postinit(self, value: NodeNG | None = None) -> None:
"""
self.value = value

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
if self.value is not None:
yield self.value

Expand Down Expand Up @@ -4346,7 +4346,7 @@ def postinit(
self.conversion = conversion
self.format_spec = format_spec

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield self.value

if self.format_spec is not None:
Expand Down Expand Up @@ -4410,7 +4410,7 @@ def postinit(self, values: list[NodeNG] | None = None) -> None:
if values is not None:
self.values = values

def get_children(self):
def get_children(self) -> Iterator[NodeNG]:
yield from self.values


Expand Down
Loading