Skip to content

Commit

Permalink
Update griffe_extensions to support Griffe v 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
waylan committed Aug 16, 2024
1 parent 33359fa commit bd836a1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions scripts/griffe_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from __future__ import annotations

import ast
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any
import textwrap

from griffe import Docstring, Extension
from griffe.docstrings.dataclasses import DocstringSectionAdmonition, DocstringSectionText
from griffe import Docstring, Extension, DocstringSectionAdmonition, DocstringSectionText, Visitor, Inspector

if TYPE_CHECKING:
from griffe import Class, Function, ObjectNode
Expand All @@ -29,13 +28,13 @@ def _insert_message(self, obj: Function | Class, message: str) -> None:
sections = obj.docstring.parsed
sections.insert(0, DocstringSectionAdmonition(kind="warning", text=message, title="Deprecated"))

def on_class_instance(self, node: ast.AST | ObjectNode, cls: Class) -> None: # noqa: ARG002
def on_class_instance(self, node: ast.AST | ObjectNode, cls: Class, agent: Visitor | Inspector, **kwargs: Any) -> None: # noqa: ARG002
"""Add section to docstrings of deprecated classes."""
if message := _deprecated(cls):
self._insert_message(cls, message)
cls.labels.add("deprecated")

def on_function_instance(self, node: ast.AST | ObjectNode, func: Function) -> None: # noqa: ARG002
def on_function_instance(self, node: ast.AST | ObjectNode, func: Function, agent: Visitor | Inspector, **kwargs: Any) -> None: # noqa: ARG002
"""Add section to docstrings of deprecated functions."""
if message := _deprecated(func):
self._insert_message(func, message)
Expand All @@ -53,7 +52,7 @@ def linked_obj(self, value: str, path: str) -> str:
""" Wrap object name in reference link. """
return f'[`{value}`][{path}.{value}]'

def on_function_instance(self, node: ast.AST | ObjectNode, func: Function) -> None: # noqa: ARG002
def on_function_instance(self, node: ast.AST | ObjectNode, func: Function, agent: Visitor | Inspector, **kwargs: Any) -> None: # noqa: ARG002
"""Add table to specified function docstrings."""
if self.paths and func.path not in self.paths:
return # skip objects that were not selected
Expand Down

0 comments on commit bd836a1

Please sign in to comment.