Skip to content

Commit

Permalink
chore: more griffe support for inspecthelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 10, 2023
1 parent e66ab2c commit 3bd88e4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mknodes/utils/inspecthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def get_deprecated_message(obj) -> str | None:
Arguments:
obj: Object to check
"""
if isinstance(obj, griffe.Function | griffe.Class):
paths = [
i for i in obj.decorators if i.callable_path == "typing_extensions.deprecated"
]
if paths:
p = str(paths[0].value)
return p[p.find("(") + 1 : p.find(")")]
return obj.__deprecated__ if hasattr(obj, "__deprecated__") else None


Expand Down Expand Up @@ -93,6 +100,18 @@ def get_doc(
return helpers.escaped(doc) if doc and escape else doc


def is_abstract(obj: type | griffe.Class | griffe.Function) -> bool:
"""Check whether a class / method is abstract."""
match obj:
case griffe.Function():
return "abc.abstractmethod" in [i.callable_path for i in obj.decorators]
case griffe.Class():
bases = [i if isinstance(i, str) else i.canonical_path for i in obj.bases]
return "abc.ABC" in bases
case _:
return inspect.isabstract(obj)


@functools.cache
def get_source(obj: datatypes.HasCodeType | griffe.Object) -> str:
"""Cached wrapper for inspect.getsource.
Expand Down

0 comments on commit 3bd88e4

Please sign in to comment.