Skip to content

Commit ffc368f

Browse files
authored
Add typing to ClassDef.ancestors (#1676)
1 parent dd93dcf commit ffc368f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

astroid/bases.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ def infer_call_result(self, caller, context=None):
288288
class Instance(BaseInstance):
289289
"""A special node representing a class instance."""
290290

291+
_proxied: nodes.ClassDef
292+
291293
# pylint: disable=unnecessary-lambda
292294
special_attributes = lazy_descriptor(lambda: objectmodel.InstanceModel())
293295

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os
1616
import sys
1717
import warnings
18-
from collections.abc import Iterator
18+
from collections.abc import Generator, Iterator
1919
from typing import TYPE_CHECKING, NoReturn, TypeVar, overload
2020

2121
from astroid import bases
@@ -2014,11 +2014,8 @@ def __init__(
20142014
:type: list(Keyword) or None
20152015
"""
20162016

2017-
self.bases = []
2018-
"""What the class inherits from.
2019-
2020-
:type: list(NodeNG)
2021-
"""
2017+
self.bases: list[NodeNG] = []
2018+
"""What the class inherits from."""
20222019

20232020
self.body = []
20242021
"""The contents of the class body.
@@ -2375,14 +2372,14 @@ def basenames(self):
23752372
"""
23762373
return [bnode.as_string() for bnode in self.bases]
23772374

2378-
def ancestors(self, recurs=True, context=None):
2375+
def ancestors(
2376+
self, recurs: bool = True, context: InferenceContext | None = None
2377+
) -> Generator[ClassDef, None, None]:
23792378
"""Iterate over the base classes in prefixed depth first order.
23802379
23812380
:param recurs: Whether to recurse or return direct ancestors only.
2382-
:type recurs: bool
23832381
23842382
:returns: The base classes
2385-
:rtype: iterable(NodeNG)
23862383
"""
23872384
# FIXME: should be possible to choose the resolution order
23882385
# FIXME: inference make infinite loops possible here

0 commit comments

Comments
 (0)