From 8b1a7edc11a72f679689fa9ba9e632907f9304f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 27 Dec 2021 21:25:38 +0100 Subject: [PATCH] refactor: Use annotation getter for base classes --- src/griffe/agents/visitor.py | 5 ++--- src/griffe/dataclasses.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/griffe/agents/visitor.py b/src/griffe/agents/visitor.py index ce5b30cc..45d2ba69 100644 --- a/src/griffe/agents/visitor.py +++ b/src/griffe/agents/visitor.py @@ -20,7 +20,6 @@ from griffe.agents.nodes import ( ASTNode, get_annotation, - get_baseclass, get_docstring, get_instance_names, get_names, @@ -219,7 +218,7 @@ def visit_classdef(self, node: ast.ClassDef) -> None: bases = [] if node.bases: for base in node.bases: - bases.append(get_baseclass(base, self.current)) + bases.append(get_annotation(base, self.current)) class_ = Class( name=node.name, @@ -227,7 +226,7 @@ def visit_classdef(self, node: ast.ClassDef) -> None: endlineno=node.end_lineno, # type: ignore[attr-defined] docstring=self._get_docstring(node), decorators=decorators, - bases=bases, + bases=bases, # type: ignore[arg-type] ) self.current[node.name] = class_ self.current = class_ diff --git a/src/griffe/dataclasses.py b/src/griffe/dataclasses.py index 1b48495d..bff5e85d 100644 --- a/src/griffe/dataclasses.py +++ b/src/griffe/dataclasses.py @@ -960,7 +960,7 @@ class Class(Object): def __init__( self, *args: Any, - bases: list[Name | Expression] | None = None, + bases: list[Name | Expression | str] | None = None, decorators: list[Decorator] | None = None, **kwargs: Any, ) -> None: @@ -973,7 +973,7 @@ def __init__( **kwargs: See [`griffe.dataclasses.Object`][]. """ super().__init__(*args, **kwargs) - self.bases: list[Name | Expression] = bases or [] + self.bases: list[Name | Expression | str] = bases or [] self.decorators: list[Decorator] = decorators or [] def as_dict(self, **kwargs: Any) -> dict[str, Any]: # type: ignore[override]