Skip to content

Commit

Permalink
feat: Add deprecated attribute and is_deprecated property to obje…
Browse files Browse the repository at this point in the history
…cts/aliases
  • Loading branch information
pawamoy committed Jun 18, 2024
1 parent 1982023 commit 2a75d84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/griffe/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ def __init__(
self.public: bool | None = None
"""Whether this object is public."""

self.deprecated: str | None = None
"""Whether this object is deprecated (boolean or deprecation message)."""

self._lines_collection: LinesCollection | None = lines_collection
self._modules_collection: ModulesCollection | None = modules_collection

Expand Down Expand Up @@ -852,6 +855,9 @@ def __init__(
self.public: bool | None = None
"""Whether this alias is public."""

self.deprecated: str | bool | None = None
"""Whether this alias is deprecated (boolean or deprecation message)."""

self._parent: Module | Class | Alias | None = parent
self._passed_through: bool = False

Expand Down
6 changes: 6 additions & 0 deletions src/griffe/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ def is_public(self) -> bool:
# If we reached this point, the object is public.
return _True # type: ignore[return-value]

@property
def is_deprecated(self) -> bool:
"""Whether this object is deprecated."""
# NOTE: We might want to add more ways to detect deprecations in the future.
return bool(self.deprecated) # type: ignore[attr-defined]


# This is used to allow the `is_public` property to be "callable",
# for backward compatibility with the previous implementation.
Expand Down

0 comments on commit 2a75d84

Please sign in to comment.