Skip to content

Commit

Permalink
refactor: Use annotation getter for base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Dec 27, 2021
1 parent 6edfc9f commit 8b1a7ed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/griffe/agents/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from griffe.agents.nodes import (
ASTNode,
get_annotation,
get_baseclass,
get_docstring,
get_instance_names,
get_names,
Expand Down Expand Up @@ -219,15 +218,15 @@ 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,
lineno=lineno,
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_
Expand Down
4 changes: 2 additions & 2 deletions src/griffe/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down

0 comments on commit 8b1a7ed

Please sign in to comment.