From fd72083fa06c3eb4ef76fe74c5126eef308766c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 15 Aug 2024 17:53:00 +0200 Subject: [PATCH] refactor: Further code clean up --- CHANGELOG.md | 2 +- src/_griffe/diff.py | 9 ------ src/_griffe/mixins.py | 69 +------------------------------------------ src/_griffe/models.py | 21 +------------ 4 files changed, 3 insertions(+), 98 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6821099..f10d1187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,7 +135,7 @@ We are still in v0, so no major bump yet. ### Deprecations - As seen above in the breaking changes section, the only parameters of [`Object.has_labels()`][griffe.Object.has_labels] and [`load_extensions()`][griffe.load_extensions] both became variadic positional parameters. Passing a sequence as single argument is deprecated in favor of passing multiple arguments. This is an ergonomic change: I myself often forgot to wrap extensions in a list. Passing sequences of labels (lists, sets, tuples) is also difficult from Jinja templates. -- The following methods and properties on objects and aliases are deprecated: [`member_is_exported()`][griffe.Object.member_is_exported], [`is_explicitely_exported`][griffe.ObjectAliasMixin.is_explicitely_exported], [`is_implicitely_exported`][griffe.ObjectAliasMixin.is_implicitely_exported]. Use the [`is_exported`][griffe.ObjectAliasMixin.is_exported] property instead. See [issue 281](https://github.com/mkdocstrings/griffe/issues/281). +- The following methods and properties on objects and aliases are deprecated: `member_is_exported()`, `is_explicitely_exported`, `is_implicitely_exported`. Use the [`is_exported`][griffe.ObjectAliasMixin.is_exported] property instead. See [issue 281](https://github.com/mkdocstrings/griffe/issues/281). - The [`is_exported()`][griffe.ObjectAliasMixin.is_exported] and [`is_public()`][griffe.ObjectAliasMixin.is_public] methods became properties. They can still be called like methods, but will emit deprecation warnings when doing so. See [issue 281](https://github.com/mkdocstrings/griffe/issues/281). - The `ignore_private` parameter of the [`find_breaking_changes()`][griffe.find_breaking_changes] function is now deprecated and unused. With the reworked "exported" and "public" API, this parameter became useless. See [issue 281](https://github.com/mkdocstrings/griffe/issues/281). - Using `stats()` instead of [`Stats`][griffe.Stats] will now emit a deprecation warning. diff --git a/src/_griffe/diff.py b/src/_griffe/diff.py index 9254bd35..c990232e 100644 --- a/src/_griffe/diff.py +++ b/src/_griffe/diff.py @@ -9,7 +9,6 @@ from __future__ import annotations import contextlib -import warnings from pathlib import Path from typing import TYPE_CHECKING, Any, Iterable, Iterator @@ -545,8 +544,6 @@ def _returns_are_compatible(old_function: Function, new_function: Function) -> b def find_breaking_changes( old_obj: Object | Alias, new_obj: Object | Alias, - *, - ignore_private: bool = _sentinel, # type: ignore[assignment] ) -> Iterator[Breakage]: """Find breaking changes between two versions of the same API. @@ -567,10 +564,4 @@ def find_breaking_changes( >>> for breakage in griffe.find_breaking_changes(old, new) ... print(breakage.explain(style=style), file=sys.stderr) """ - if ignore_private is not _sentinel: - warnings.warn( - "The `ignore_private` parameter is deprecated and will be removed in a future version.", - DeprecationWarning, - stacklevel=2, - ) yield from _member_incompatibilities(old_obj, new_obj) diff --git a/src/_griffe/mixins.py b/src/_griffe/mixins.py index 37475d3a..8957920a 100644 --- a/src/_griffe/mixins.py +++ b/src/_griffe/mixins.py @@ -4,7 +4,6 @@ from __future__ import annotations import json -import warnings from contextlib import suppress from typing import TYPE_CHECKING, Any, Sequence, TypeVar @@ -331,26 +330,6 @@ def attributes(self) -> dict[str, Attribute]: """ return {name: member for name, member in self.all_members.items() if member.kind is Kind.ATTRIBUTE} # type: ignore[misc] - @property - def has_private_name(self) -> bool: - """Deprecated. Use [`is_private`][griffe.Object.is_private] instead.""" - warnings.warn( - "The `has_private_name` property is deprecated. Use `is_private` instead.", - DeprecationWarning, - stacklevel=2, - ) - return self.name.startswith("_") # type: ignore[attr-defined] - - @property - def has_special_name(self) -> bool: - """Deprecated. Use [`is_special`][griffe.Object.is_special] instead.""" - warnings.warn( - "The `has_special_name` property is deprecated. Use `is_special` instead.", - DeprecationWarning, - stacklevel=2, - ) - return self.name.startswith("__") and self.name.endswith("__") # type: ignore[attr-defined] - @property def is_private(self) -> bool: """Whether this object/alias is private (starts with `_`) but not special.""" @@ -374,28 +353,7 @@ def is_imported(self) -> bool: @property def is_exported(self) -> bool: """Whether this object/alias is exported (listed in `__all__`).""" - result = self.parent.is_module and bool(self.parent.exports and self.name in self.parent.exports) # type: ignore[attr-defined] - return _True if result else _False # type: ignore[return-value] - - @property - def is_explicitely_exported(self) -> bool: - """Deprecated. Use the [`is_exported`][griffe.ObjectAliasMixin.is_exported] property instead.""" - warnings.warn( - "The `is_explicitely_exported` property is deprecated. Use `is_exported` instead.", - DeprecationWarning, - stacklevel=2, - ) - return self.is_exported - - @property - def is_implicitely_exported(self) -> bool: - """Deprecated. Use the [`is_exported`][griffe.ObjectAliasMixin.is_exported] property instead.""" - warnings.warn( - "The `is_implicitely_exported` property is deprecated. Use `is_exported` instead.", - DeprecationWarning, - stacklevel=2, - ) - return self.is_exported + return self.parent.is_module and bool(self.parent.exports and self.name in self.parent.exports) # type: ignore[attr-defined] @property def is_wildcard_exposed(self) -> bool: @@ -479,28 +437,3 @@ 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. -class _Bool: - def __init__(self, value: bool) -> None: # noqa: FBT001 - self.value = value - - def __bool__(self) -> bool: - return self.value - - def __repr__(self) -> str: - return repr(self.value) - - def __call__(self, *args: Any, **kwargs: Any) -> bool: # noqa: ARG002 - warnings.warn( - "This method is now a property and should be accessed as such (without parentheses).", - DeprecationWarning, - stacklevel=2, - ) - return self.value - - -_True = _Bool(True) # noqa: FBT003 -_False = _Bool(False) # noqa: FBT003 diff --git a/src/_griffe/models.py b/src/_griffe/models.py index 1eacc026..cdba6053 100644 --- a/src/_griffe/models.py +++ b/src/_griffe/models.py @@ -4,7 +4,6 @@ from __future__ import annotations import inspect -import warnings from collections import defaultdict from contextlib import suppress from pathlib import Path @@ -405,7 +404,7 @@ def __init__( self.public: bool | None = None """Whether this object is public.""" - self.deprecated: str | None = None + self.deprecated: bool | str | None = None """Whether this object is deprecated (boolean or deprecation message).""" self._lines_collection: LinesCollection | None = lines_collection @@ -457,15 +456,6 @@ def has_docstrings(self) -> bool: continue return False - def member_is_exported(self, member: Object | Alias, *, explicitely: bool = True) -> bool: # noqa: ARG002 - """Deprecated. Use [`member.is_exported`][griffe.Object.is_exported] instead.""" - warnings.warn( - "Method `member_is_exported` is deprecated. Use `member.is_exported` instead.", - DeprecationWarning, - stacklevel=2, - ) - return member.is_exported - def is_kind(self, kind: str | Kind | set[str | Kind]) -> bool: """Tell if this object is of the given kind. @@ -1095,15 +1085,6 @@ def aliases(self) -> dict[str, Alias]: """The aliases pointing to this object.""" return self.final_target.aliases - def member_is_exported(self, member: Object | Alias, *, explicitely: bool = True) -> bool: # noqa: ARG002 - """Deprecated. Use [`member.is_exported`][griffe.Alias.is_exported] instead.""" - warnings.warn( - "Method `member_is_exported` is deprecated. Use `member.is_exported` instead.", - DeprecationWarning, - stacklevel=2, - ) - return member.is_exported - def is_kind(self, kind: str | Kind | set[str | Kind]) -> bool: """Tell if this object is of the given kind.