Skip to content

Commit

Permalink
refactor: Further code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Aug 15, 2024
1 parent 86d321e commit fd72083
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 98 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 0 additions & 9 deletions src/_griffe/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from __future__ import annotations

import contextlib
import warnings
from pathlib import Path
from typing import TYPE_CHECKING, Any, Iterable, Iterator

Expand Down Expand Up @@ -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.
Expand All @@ -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)
69 changes: 1 addition & 68 deletions src/_griffe/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

import json
import warnings
from contextlib import suppress
from typing import TYPE_CHECKING, Any, Sequence, TypeVar

Expand Down Expand Up @@ -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."""
Expand All @@ -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:
Expand Down Expand Up @@ -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
21 changes: 1 addition & 20 deletions src/_griffe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

import inspect
import warnings
from collections import defaultdict
from contextlib import suppress
from pathlib import Path
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fd72083

Please sign in to comment.