summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-06-29 23:18:45 +0200
committerGitHub <noreply@github.com>2022-06-29 23:18:45 +0200
commitffc368f1c1fe17e306a88be56ba0ca13fe85f9a5 (patch)
treede850dedc3c6e1cd4f0aca9521f78ce0e9206c6a
parentdd93dcfa6a9c636b6f11f0ea373ec0ddf043787f (diff)
downloadastroid-git-ffc368f1c1fe17e306a88be56ba0ca13fe85f9a5.tar.gz
Add typing to `ClassDef.ancestors` (#1676)
-rw-r--r--astroid/bases.py2
-rw-r--r--astroid/nodes/scoped_nodes/scoped_nodes.py15
2 files changed, 8 insertions, 9 deletions
diff --git a/astroid/bases.py b/astroid/bases.py
index e20d912a..a3f2017f 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -288,6 +288,8 @@ class BaseInstance(Proxy):
class Instance(BaseInstance):
"""A special node representing a class instance."""
+ _proxied: nodes.ClassDef
+
# pylint: disable=unnecessary-lambda
special_attributes = lazy_descriptor(lambda: objectmodel.InstanceModel())
diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py
index 5eea0aa9..061c52ca 100644
--- a/astroid/nodes/scoped_nodes/scoped_nodes.py
+++ b/astroid/nodes/scoped_nodes/scoped_nodes.py
@@ -15,7 +15,7 @@ import itertools
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
@@ -2014,11 +2014,8 @@ class ClassDef(
: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.
@@ -2375,14 +2372,14 @@ class ClassDef(
"""
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