Skip to content

Commit

Permalink
build: Depend on Griffe 0.49
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Aug 14, 2024
1 parent f063178 commit b6d7bd9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
"Typing :: Typed",
]
dependencies = [
"griffe>=0.38",
"griffe>=0.49",
"typing-extensions>=4.7",
]

Expand Down
5 changes: 2 additions & 3 deletions src/griffe_typingdoc/_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import TYPE_CHECKING, Any, Iterator

from griffe.docstrings.dataclasses import (
from griffe import (
DocstringParameter,
DocstringRaise,
DocstringReceive,
Expand All @@ -22,8 +22,7 @@
)

if TYPE_CHECKING:
from griffe import Function
from griffe.dataclasses import Parameter
from griffe import Function, Parameter


def _no_self_params(func: Function) -> list[Parameter]:
Expand Down
11 changes: 7 additions & 4 deletions src/griffe_typingdoc/_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from griffe import Docstring, Extension, Function, ObjectNode

Expand Down Expand Up @@ -107,11 +107,11 @@ def _handle_object(self, obj: Object) -> None:
return
if obj.is_module or obj.is_class:
for member in obj.members.values():
self._handle_object(member) # type: ignore[arg-type]
self._handle_object(member)
elif obj.is_function:
self._handle_function(obj) # type: ignore[arg-type]
self._handle_function(obj)
elif obj.is_attribute:
self._handle_attribute(obj) # type: ignore[arg-type]
self._handle_attribute(obj)

def on_package_loaded(
self,
Expand All @@ -120,6 +120,7 @@ def on_package_loaded(
Module,
Doc("The top-level module representing a package."),
],
**kwargs: Any, # noqa: ARG002
) -> None:
"""Post-process Griffe packages recursively (non-yet handled objects only)."""
self._handle_object(pkg)
Expand All @@ -135,6 +136,7 @@ def on_function_instance(
Function,
Doc("""The Griffe function just instantiated."""),
],
**kwargs: Any, # noqa: ARG002
) -> None:
"""Post-process Griffe functions to add a parameters section.
Expand All @@ -154,6 +156,7 @@ def on_attribute_instance(
Attribute,
Doc("The Griffe attribute just instantiated."),
],
**kwargs: Any, # noqa: ARG002
) -> None:
"""Post-process Griffe attributes to create their docstring.
Expand Down
9 changes: 4 additions & 5 deletions src/griffe_typingdoc/_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from collections import defaultdict
from typing import TYPE_CHECKING, Any, Sequence

from griffe.enumerations import ParameterKind
from griffe.expressions import Expr, ExprCall, ExprSubscript, ExprTuple
from griffe import Expr, ExprCall, ExprSubscript, ExprTuple, ParameterKind

from griffe_typingdoc._docstrings import (
_no_self_params,
Expand Down Expand Up @@ -213,7 +212,7 @@ def _warns_docs(attr_or_func: Attribute | Function, **kwargs: Any) -> DocstringS
if attr_or_func.is_attribute:
annotation = attr_or_func.annotation
elif attr_or_func.is_function:
annotation = attr_or_func.returns # type: ignore[union-attr]
annotation = attr_or_func.returns
metadata = _metadata(annotation)
if metadata["warns"]:
return _to_warns_section({"annotation": warned[0], "description": warned[1]} for warned in metadata["warns"])
Expand All @@ -224,7 +223,7 @@ def _raises_docs(attr_or_func: Attribute | Function, **kwargs: Any) -> Docstring
if attr_or_func.is_attribute:
annotation = attr_or_func.annotation
elif attr_or_func.is_function:
annotation = attr_or_func.returns # type: ignore[union-attr]
annotation = attr_or_func.returns
metadata = _metadata(annotation)
if metadata["raises"]:
return _to_raises_section({"annotation": raised[0], "description": raised[1]} for raised in metadata["raises"])
Expand All @@ -238,7 +237,7 @@ def _deprecated_docs(
if attr_or_func.is_attribute:
annotation = attr_or_func.annotation
elif attr_or_func.is_function:
annotation = attr_or_func.returns # type: ignore[union-attr]
annotation = attr_or_func.returns
metadata = _metadata(annotation)
if "deprecated" in metadata:
return _to_deprecated_section({"description": metadata["deprecated"]})
Expand Down
10 changes: 4 additions & 6 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Tests for the Griffe extension."""

from griffe.docstrings.dataclasses import DocstringSectionKind
from griffe.extensions import Extensions
from griffe.loader import GriffeLoader
from griffe.tests import temporary_visited_package
from griffe import DocstringSectionKind, Extensions, GriffeLoader, temporary_visited_package

from griffe_typingdoc import TypingDocExtension

typing_imports = "from typing import Annotated, Doc, Generator, Iterator, Name, NotRequired, Raises, TypedDict, Unpack, Warns"
typing_imports = (
"from typing import Annotated, Doc, Generator, Iterator, Name, NotRequired, Raises, TypedDict, Unpack, Warns"
)
warning_imports = "from warnings import deprecated"


Expand Down Expand Up @@ -41,7 +40,6 @@ def test_parameter_doc() -> None:
assert package["f"].docstring.parsed[1].value[0].description == "Hello."



def test_other_parameter_doc() -> None:
"""Read documentation for other parameters, in unpack/typeddict annotations."""
with temporary_visited_package(
Expand Down

0 comments on commit b6d7bd9

Please sign in to comment.