Skip to content

Commit

Permalink
Add typing to ClassDef.ancestors (#1676)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord authored Jun 29, 2022
1 parent dd93dcf commit ffc368f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def infer_call_result(self, caller, context=None):
class Instance(BaseInstance):
"""A special node representing a class instance."""

_proxied: nodes.ClassDef

# pylint: disable=unnecessary-lambda
special_attributes = lazy_descriptor(lambda: objectmodel.InstanceModel())

Expand Down
15 changes: 6 additions & 9 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import sys
import warnings
from collections.abc import Iterator
from collections.abc import Generator, Iterator
from typing import TYPE_CHECKING, NoReturn, TypeVar, overload

from astroid import bases
Expand Down Expand Up @@ -2014,11 +2014,8 @@ def __init__(
:type: list(Keyword) or None
"""

self.bases = []
"""What the class inherits from.
:type: list(NodeNG)
"""
self.bases: list[NodeNG] = []
"""What the class inherits from."""

self.body = []
"""The contents of the class body.
Expand Down Expand Up @@ -2375,14 +2372,14 @@ def basenames(self):
"""
return [bnode.as_string() for bnode in self.bases]

def ancestors(self, recurs=True, context=None):
def ancestors(
self, recurs: bool = True, context: InferenceContext | None = None
) -> Generator[ClassDef, None, None]:
"""Iterate over the base classes in prefixed depth first order.
:param recurs: Whether to recurse or return direct ancestors only.
:type recurs: bool
:returns: The base classes
:rtype: iterable(NodeNG)
"""
# FIXME: should be possible to choose the resolution order
# FIXME: inference make infinite loops possible here
Expand Down

0 comments on commit ffc368f

Please sign in to comment.