diff --git a/docs/guide/contributors/workflow.md b/docs/guide/contributors/workflow.md index 0e6064a49..62d2ff5f4 100644 --- a/docs/guide/contributors/workflow.md +++ b/docs/guide/contributors/workflow.md @@ -57,10 +57,6 @@ Deprecated code should also be marked as legacy code. We use [Yore](https://pawa Examples: ```python title="Remove function when we bump to 2.0" -# YORE: Bump 2: Remove block. -def deprecated_function(): - ... -``` ```python title="Simplify imports when Python 3.15 is EOL" # YORE: EOL 3.15: Replace block with line 4. diff --git a/docs/reference/api/agents.md b/docs/reference/api/agents.md index 224426697..ca7f50c4d 100644 --- a/docs/reference/api/agents.md +++ b/docs/reference/api/agents.md @@ -70,8 +70,4 @@ Griffe is able to analyze code both statically and dynamically. ::: griffe.safe_get_value - -## **Deprecated API** - -::: griffe.ExportedName diff --git a/docs/reference/api/git.md b/docs/reference/api/git.md deleted file mode 100644 index 7abc81fcf..000000000 --- a/docs/reference/api/git.md +++ /dev/null @@ -1,13 +0,0 @@ -# Git utilities - - - -DANGER: **Deprecated utilities.** We have decided to stop exposing Git-related utilities as it's not a core part of the library's functionality. The functions documented on this page will become unavailable in the next major version. - -::: griffe.assert_git_repo - -::: griffe.get_latest_tag - -::: griffe.get_repo_root - -::: griffe.tmp_worktree diff --git a/duties.py b/duties.py index 21fc7fccb..d3f1178cd 100644 --- a/duties.py +++ b/duties.py @@ -291,8 +291,6 @@ def check_api(ctx: Context, *cli_args: str) -> None: color=True, extensions=[ "griffe_inherited_docstrings", - # YORE: Bump 2: Remove line. - "scripts/griffe_exts.py", "unpack_typeddict", ], ).add_args(*cli_args), diff --git a/mkdocs.yml b/mkdocs.yml index e9d7447e2..0ca192944 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -110,8 +110,6 @@ nav: - Parsers: reference/api/docstrings/parsers.md - Exceptions: reference/api/exceptions.md - Expressions: reference/api/expressions.md - # YORE: Bump 2: Remove line. - - Git utilities: reference/api/git.md - Loggers: reference/api/loggers.md - Helpers: reference/api/helpers.md - Changelog: changelog.md @@ -231,8 +229,6 @@ plugins: docstring_section_style: list extensions: - griffe_inherited_docstrings - # YORE: Bump 2: Remove line. - - scripts/griffe_exts.py - unpack_typeddict heading_level: 2 inherited_members: true diff --git a/scripts/griffe_exts.py b/scripts/griffe_exts.py deleted file mode 100644 index b9d0a5b5a..000000000 --- a/scripts/griffe_exts.py +++ /dev/null @@ -1,24 +0,0 @@ -# YORE: Bump 2: Remove file. - -from typing import Any - -import griffe - - -class ModuleGetAttrExtension(griffe.Extension): - def on_package(self, *, pkg: griffe.Module, **kwargs: Any) -> None: # noqa: ARG002,D102 - if pkg.name == "griffe": - for name in griffe._deprecated_names: - try: - target = pkg[f"_internal.git._{name}"] - except KeyError: - # Old version where the utility was not yet renamed. - continue - pkg.set_member(name, griffe.Alias(name, target=f"griffe._internal.git._{name}")) - admonition = griffe.DocstringSectionAdmonition( - kind="danger", - text="", - title="This function is deprecated and will become unavailable in the next major version.", - ) - target.docstring.parsed.insert(1, admonition) - target.labels.add("deprecated") diff --git a/src/griffe/__init__.py b/src/griffe/__init__.py index 21e9d8006..c06aad3a3 100644 --- a/src/griffe/__init__.py +++ b/src/griffe/__init__.py @@ -164,9 +164,6 @@ from __future__ import annotations -import warnings -from typing import Any - from griffe._internal.agents.inspector import Inspector, inspect from griffe._internal.agents.nodes.assignments import get_instance_names, get_name, get_names from griffe._internal.agents.nodes.ast import ( @@ -181,9 +178,7 @@ ast_siblings, ) from griffe._internal.agents.nodes.docstrings import get_docstring - -# YORE: Bump 2: Replace `ExportedName, ` with `` within line. -from griffe._internal.agents.nodes.exports import ExportedName, get__all__, safe_get__all__ +from griffe._internal.agents.nodes.exports import get__all__, safe_get__all__ from griffe._internal.agents.nodes.imports import relative_to_absolute from griffe._internal.agents.nodes.parameters import ParametersType, get_parameters from griffe._internal.agents.nodes.runtime import ObjectNode @@ -383,33 +378,9 @@ vtree, ) -# YORE: Bump 2: Remove block. -_deprecated_names = ( - "assert_git_repo", - "get_latest_tag", - "get_repo_root", - "tmp_worktree", -) - - -# YORE: Bump 2: Remove block. -def __getattr__(name: str) -> Any: - if name in _deprecated_names: - from griffe._internal import git # noqa: PLC0415 - - warnings.warn( - f"The `{name}` function is deprecated and will become unavailable in the next major version.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(git, f"_{name}") - - raise AttributeError(f"module '{__name__}' has no attribute '{name}'") - - # Regenerate this list with the following Python snippet: # import griffe -# names = sorted(n for n in dir(griffe) if not n.startswith("_") and n not in ("Any", "annotations", "lazy_importing", "warnings")) +# names = sorted(n for n in dir(griffe) if not n.startswith("_") and n not in ("annotations",)) # print('__all__ = [\n "' + '",\n "'.join(names) + '",\n]') __all__ = [ "DEFAULT_LOG_LEVEL", @@ -468,8 +439,6 @@ def __getattr__(name: str) -> Any: "DocstringWarn", "DocstringYield", "ExplanationStyle", - # YORE: Bump 2: Remove line. - "ExportedName", "Expr", "ExprAttribute", "ExprBinOp", @@ -565,7 +534,6 @@ def __getattr__(name: str) -> Any: "UnimportableModuleError", "UnpackTypedDictExtension", "Visitor", - "assert_git_repo", "ast_children", "ast_first_child", "ast_kind", @@ -591,13 +559,11 @@ def __getattr__(name: str) -> Any: "get_docstring", "get_expression", "get_instance_names", - "get_latest_tag", "get_logger", "get_name", "get_names", "get_parameters", "get_parser", - "get_repo_root", "get_value", "htree", "infer_docstring_style", @@ -635,7 +601,6 @@ def __getattr__(name: str) -> Any: "temporary_pypackage", "temporary_visited_module", "temporary_visited_package", - "tmp_worktree", "typing_overload", "visit", "vtree", diff --git a/src/griffe/_internal/agents/nodes/exports.py b/src/griffe/_internal/agents/nodes/exports.py index f2e9caff3..d726e9c03 100644 --- a/src/griffe/_internal/agents/nodes/exports.py +++ b/src/griffe/_internal/agents/nodes/exports.py @@ -4,7 +4,6 @@ import ast from contextlib import suppress -from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Callable from griffe._internal.agents.nodes.values import get_value @@ -16,20 +15,6 @@ from griffe._internal.models import Module -# YORE: Bump 2: Remove block. -@dataclass -class ExportedName: - """Deprecated. An intermediate class to store names. - - The [`get__all__`][griffe.get__all__] function now returns instances of [`ExprName`][griffe.ExprName] instead. - """ - - name: str - """The exported name.""" - parent: Module - """The parent module.""" - - def _extract_attribute(node: ast.Attribute, parent: Module) -> list[str | ExprName]: return [ExprName(name=node.attr, parent=_extract(node.value, parent)[0])] diff --git a/src/griffe/_internal/docstrings/auto.py b/src/griffe/_internal/docstrings/auto.py index ecd3a1d66..761dfceb0 100644 --- a/src/griffe/_internal/docstrings/auto.py +++ b/src/griffe/_internal/docstrings/auto.py @@ -3,8 +3,7 @@ from __future__ import annotations import re -from typing import TYPE_CHECKING, Any, Literal, TypedDict -from warnings import warn +from typing import TYPE_CHECKING, Literal, TypedDict from griffe._internal.enumerations import Parser @@ -121,8 +120,6 @@ def infer_docstring_style( style_order: list[Parser] | list[DocstringStyle] | None = None, default: Parser | DocstringStyle | None = None, per_style_options: PerStyleOptions | None = None, - # YORE: Bump 2: Remove line. - **options: Any, ) -> tuple[Parser | None, list[DocstringSection] | None]: """Infer the parser to use for the docstring. @@ -142,21 +139,13 @@ def infer_docstring_style( style_order: The order of the styles to try when inferring the parser. default: The default parser to use if the inference fails. per_style_options: Additional parsing options per style. - **options: Deprecated. Use `per_style_options` instead. Returns: The inferred parser, and optionally parsed sections (when method is 'max_sections'). """ from griffe._internal.docstrings.parsers import parsers # noqa: PLC0415 - # YORE: Bump 2: Replace block with `per_style_options = per_style_options or {}`. - if options: - if per_style_options: - raise ValueError("Cannot use both `options` and `per_style_options`.") - warn("`**options` is deprecated. Use `per_style_options` instead.", DeprecationWarning, stacklevel=2) - per_style_options = {"google": options, "numpy": options, "sphinx": options} # type: ignore[assignment] - elif not per_style_options: - per_style_options = {} + per_style_options = per_style_options or {} style_order = [Parser(style) if isinstance(style, str) else style for style in style_order or _default_style_order] @@ -203,8 +192,6 @@ def parse_auto( style_order: list[Parser] | list[DocstringStyle] | None = None, default: Parser | DocstringStyle | None = None, per_style_options: PerStyleOptions | None = None, - # YORE: Bump 2: Remove line. - **options: Any, ) -> list[DocstringSection]: """Parse a docstring by automatically detecting the style it uses. @@ -217,21 +204,13 @@ def parse_auto( style_order: The order of the styles to try when inferring the parser. default: The default parser to use if the inference fails. per_style_options: Additional parsing options per style. - **options: Deprecated. Use `per_style_options` instead. Returns: A list of docstring sections. """ from griffe._internal.docstrings.parsers import parse # noqa: PLC0415 - # YORE: Bump 2: Replace block with `per_style_options = per_style_options or {}`. - if options: - if per_style_options: - raise ValueError("Cannot use both `options` and `per_style_options`.") - warn("`**options` are deprecated. Use `per_style_options` instead.", DeprecationWarning, stacklevel=2) - per_style_options = {"google": options, "numpy": options, "sphinx": options} # type: ignore[assignment] - elif not per_style_options: - per_style_options = {} + per_style_options = per_style_options or {} style, sections = infer_docstring_style( docstring, diff --git a/src/griffe/_internal/docstrings/google.py b/src/griffe/_internal/docstrings/google.py index 5b9b542af..42dd73b54 100644 --- a/src/griffe/_internal/docstrings/google.py +++ b/src/griffe/_internal/docstrings/google.py @@ -5,7 +5,6 @@ import re from contextlib import suppress from typing import TYPE_CHECKING, TypedDict -from warnings import warn from griffe._internal.docstrings.models import ( DocstringAttribute, @@ -892,8 +891,6 @@ def parse_google( warn_unknown_params: bool = True, warn_missing_types: bool = True, warnings: bool = True, - # YORE: Bump 2: Remove line. - **options: Any, ) -> list[DocstringSection]: """Parse a Google-style docstring. @@ -921,7 +918,6 @@ def parse_google( warn_unknown_params: Warn about documented parameters not appearing in the signature. warn_missing_types: Warn about missing types/annotations for parameters, return values, etc. warnings: Whether to log warnings at all. - **options: Swallowing keyword arguments for backward-compatibility. Returns: A list of docstring sections. @@ -932,10 +928,6 @@ def parse_google( in_code_block = False lines = docstring.lines - # YORE: Bump 2: Remove block. - if options: - warn("Passing additional options is deprecated, these options are ignored.", DeprecationWarning, stacklevel=2) - options = { "ignore_init_summary": ignore_init_summary, "trim_doctest_flags": trim_doctest_flags, diff --git a/src/griffe/_internal/docstrings/numpy.py b/src/griffe/_internal/docstrings/numpy.py index 1291f1723..080b7f63e 100644 --- a/src/griffe/_internal/docstrings/numpy.py +++ b/src/griffe/_internal/docstrings/numpy.py @@ -23,7 +23,6 @@ from contextlib import suppress from textwrap import dedent from typing import TYPE_CHECKING, TypedDict -from warnings import warn from griffe._internal.docstrings.models import ( DocstringAttribute, @@ -916,8 +915,6 @@ def parse_numpy( warn_unknown_params: bool = True, warn_missing_types: bool = True, warnings: bool = True, - # YORE: Bump 2: Remove line. - **options: Any, ) -> list[DocstringSection]: """Parse a Numpydoc-style docstring. @@ -931,7 +928,6 @@ def parse_numpy( warn_unknown_params: Warn about documented parameters not appearing in the signature. warn_missing_types: Warn about missing types/annotations for parameters, return values, etc. warnings: Whether to log warnings at all. - **options: Swallowing keyword arguments for backward-compatibility. Returns: A list of docstring sections. @@ -943,10 +939,6 @@ def parse_numpy( in_code_block = False lines = docstring.lines - # YORE: Bump 2: Remove block. - if options: - warn("Passing additional options is deprecated, these options are ignored.", DeprecationWarning, stacklevel=2) - options = { "trim_doctest_flags": trim_doctest_flags, "ignore_init_summary": ignore_init_summary, diff --git a/src/griffe/_internal/docstrings/sphinx.py b/src/griffe/_internal/docstrings/sphinx.py index 7059169bc..052758c5c 100644 --- a/src/griffe/_internal/docstrings/sphinx.py +++ b/src/griffe/_internal/docstrings/sphinx.py @@ -9,7 +9,6 @@ from contextlib import suppress from dataclasses import dataclass, field from typing import TYPE_CHECKING, Any, Callable, TypedDict -from warnings import warn from griffe._internal.docstrings.models import ( DocstringAttribute, @@ -98,8 +97,6 @@ def parse_sphinx( *, warn_unknown_params: bool = True, warnings: bool = True, - # YORE: Bump 2: Remove line. - **options: Any, ) -> list[DocstringSection]: """Parse a Sphinx-style docstring. @@ -107,17 +104,12 @@ def parse_sphinx( docstring: The docstring to parse. warn_unknown_params: Warn about documented parameters not appearing in the signature. warnings: Whether to log warnings at all. - **options: Swallowing keyword arguments for backward-compatibility. Returns: A list of docstring sections. """ parsed_values = _ParsedValues() - # YORE: Bump 2: Remove block. - if options: - warn("Passing additional options is deprecated, these options are ignored.", DeprecationWarning, stacklevel=2) - options = { "warn_unknown_params": warn_unknown_params, "warnings": warnings, diff --git a/src/griffe/_internal/encoders.py b/src/griffe/_internal/encoders.py index d485e2a17..3f148dff4 100644 --- a/src/griffe/_internal/encoders.py +++ b/src/griffe/_internal/encoders.py @@ -202,11 +202,7 @@ def _load_module(obj_dict: dict[str, Any]) -> Module: runtime=obj_dict.get("runtime", True), analysis=obj_dict.get("analysis"), ) - # YORE: Bump 2: Replace line with `members = obj_dict.get("members", {}).values()`. - members = obj_dict.get("members", []) - # YORE: Bump 2: Remove block. - if isinstance(members, dict): - members = members.values() + members = obj_dict.get("members", {}).values() for module_member in members: module.set_member(module_member.name, module_member) @@ -234,11 +230,7 @@ def _load_class(obj_dict: dict[str, Any]) -> Class: runtime=obj_dict.get("runtime", True), analysis=obj_dict.get("analysis"), ) - # YORE: Bump 2: Replace line with `members = obj_dict.get("members", {}).values()`. - members = obj_dict.get("members", []) - # YORE: Bump 2: Remove block. - if isinstance(members, dict): - members = members.values() + members = obj_dict.get("members", {}).values() for class_member in members: class_.set_member(class_member.name, class_member) diff --git a/src/griffe/_internal/extensions/base.py b/src/griffe/_internal/extensions/base.py index 8f67da61e..08cc8f64a 100644 --- a/src/griffe/_internal/extensions/base.py +++ b/src/griffe/_internal/extensions/base.py @@ -3,11 +3,8 @@ from __future__ import annotations -import inspect import os import sys -import warnings -from contextlib import suppress from importlib.util import module_from_spec, spec_from_file_location from inspect import isclass from pathlib import Path @@ -28,40 +25,7 @@ from griffe._internal.models import Alias, Attribute, Class, Function, Module, Object, TypeAlias -# YORE: Bump 2: Remove block. -class _ExtensionMetaclass(type): - """Metaclass for Griffe extensions.""" - - def __new__(cls, name: str, bases: tuple[type, ...], attrs: dict[str, Any]) -> _ExtensionMetaclass: - if "on_package_loaded" in attrs: - warnings.warn( - "The `on_package_loaded` event is deprecated and renamed to `on_package`.", - DeprecationWarning, - stacklevel=2, - ) - if "on_alias" in attrs: - parameters = inspect.signature(attrs["on_alias"]).parameters - if "node" in parameters or "agent" in parameters: - attrs["__old_on_alias"] = True - warnings.warn( - "The `on_alias` event is now a load event and receives the `alias` and `loader` parameters. " - "It doesn't receive the `node` or `agent` parameters anymore. " - "Please use the new `on_alias` signature, or rename your hook to `on_alias_instance`.", - DeprecationWarning, - stacklevel=1, - ) - if "on_wildcard_expansion" in attrs: - warnings.warn( - "The `on_wildcard_expansion` event is deprecated. " - "Instead, hook onto the `on_alias` event " - "and check for aliases' `wildcard_imported` boolean attribute.", - DeprecationWarning, - stacklevel=2, - ) - return super().__new__(cls, name, bases, attrs) - - -class Extension(metaclass=_ExtensionMetaclass): +class Extension: """Base class for Griffe extensions.""" def visit(self, node: ast.AST) -> None: @@ -469,9 +433,6 @@ def on_package(self, *, pkg: Module, loader: GriffeLoader, **kwargs: Any) -> Non loader: The loader currently in use. **kwargs: For forward-compatibility. """ - # YORE: Bump 2: Remove block. - if hasattr(self, "on_package_loaded"): - self.on_package_loaded(pkg=pkg, loader=loader, **kwargs) LoadableExtensionType = Union[str, dict[str, Any], Extension, type[Extension]] @@ -510,12 +471,7 @@ def call(self, event: str, **kwargs: Any) -> None: **kwargs: Arguments passed to the hook. """ for extension in self._extensions: - # YORE: Bump 2: Replace block with line 5. - if event == "on_alias" and getattr(extension, "__old_on_alias", False): - with suppress(TypeError): - getattr(extension, event)(**kwargs) - else: - getattr(extension, event, self._noop)(**kwargs) + getattr(extension, event, self._noop)(**kwargs) builtin_extensions: set[str] = { @@ -647,7 +603,7 @@ def load_extensions(*exts: LoadableExtensionType) -> Extensions: # TODO: Deprecate and remove at some point? # Always add our built-in dataclasses extension. - from griffe._internal.extensions.dataclasses import DataclassesExtension # noqa: PLC0415 + from griffe._internal.extensions.dataclasses import DataclassesExtension # noqa: PLC0415 for ext in extensions._extensions: if type(ext) is DataclassesExtension: diff --git a/src/griffe/_internal/loader.py b/src/griffe/_internal/loader.py index cfe2be80c..b2a2d45b5 100644 --- a/src/griffe/_internal/loader.py +++ b/src/griffe/_internal/loader.py @@ -446,8 +446,6 @@ def expand_wildcards( # Everything went right (supposedly), we add the alias as a member of the current object. obj.set_member(new_member.name, alias) - # YORE: Bump 2: Remove line. - self.extensions.call("on_wildcard_expansion", alias=alias, loader=self) def resolve_module_aliases( self, diff --git a/tests/test_api.py b/tests/test_api.py index 6fad5e4ad..0cd72b0a5 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -21,8 +21,6 @@ def _fixture_loader() -> griffe.GriffeLoader: loader = griffe.GriffeLoader( extensions=griffe.load_extensions( "griffe_inherited_docstrings", - # YORE: Bump 2: Remove line. - "scripts/griffe_exts.py", "unpack_typeddict", ), ) diff --git a/tests/test_extensions/test_base.py b/tests/test_extensions/test_base.py index b3dce656e..7ca78dee4 100644 --- a/tests/test_extensions/test_base.py +++ b/tests/test_extensions/test_base.py @@ -12,9 +12,7 @@ Alias, Extension, GriffeLoader, - Inspector, ObjectNode, - Visitor, load_extensions, temporary_visited_module, temporary_visited_package, @@ -197,84 +195,6 @@ def method(self): ... assert set(events) == set(extension.records) -# YORE: Bump 2: Remove block. -def test_on_alias_renamed_to_on_alias_instance() -> None: - """Hook still runs, a deprecation warning is emitted when the class is declared.""" - with pytest.warns(DeprecationWarning, match="`on_alias` event is now a load event"): - - class Ext(Extension): - def __init__(self) -> None: - self.records: list[str] = [] - - def on_alias( # type: ignore[override] - self, - *, - node: ast.AST | ObjectNode, # noqa: ARG002 - alias: Alias, # noqa: ARG002 - agent: Visitor | Inspector, # noqa: ARG002 - **kwargs: Any, # noqa: ARG002 - ) -> None: - self.records.append("called as on_alias_instance") - - extension = Ext() - with temporary_visited_module("import x", extensions=load_extensions(extension)): - assert extension.records == ["called as on_alias_instance"] - - -# YORE: Bump 2: Remove block. -def test_new_on_alias_event() -> None: - """No deprecation warning, hook is correctly called.""" - - class Ext(Extension): - def __init__(self) -> None: - self.records: list[str] = [] - - def on_alias(self, *, alias: Alias, loader: GriffeLoader, **kwargs: Any) -> None: # noqa: ARG002 - self.records.append("called as on_alias") - - extension = Ext() - with temporary_visited_package("pkg", {"__init__.py": "import x"}, extensions=load_extensions(extension)): - assert extension.records == ["called as on_alias"] - - -# YORE: Bump 2: Remove block. -def test_deprecated_on_package_loaded_event() -> None: - """Hook still runs, a deprecation warning is emitted when the class is declared.""" - with pytest.warns(DeprecationWarning, match="`on_package_loaded` event is deprecated and renamed"): - - class Ext(Extension): - def __init__(self) -> None: - self.records: list[str] = [] - - def on_package_loaded(self, *, pkg: Module, loader: GriffeLoader, **kwargs: Any) -> None: # noqa: ARG002 - self.records.append("called as on_package") - - extension = Ext() - with temporary_visited_package("pkg", {}, extensions=load_extensions(extension)): - assert extension.records == ["called as on_package"] - - -# YORE: Bump 2: Remove block. -def test_deprecated_on_wildcard_expansion_event() -> None: - """Hook still runs, a deprecation warning is emitted when the class is declared.""" - with pytest.warns(DeprecationWarning, match="`on_wildcard_expansion` event is deprecated"): - - class Ext(Extension): - def __init__(self) -> None: - self.records: list[str] = [] - - def on_wildcard_expansion(self, *, alias: Alias, loader: GriffeLoader, **kwargs: Any) -> None: # noqa: ARG002 - self.records.append("called as on_wildcard_expansion") - - extension = Ext() - with temporary_visited_package( - "pkg", - {"__init__.py": "from pkg.module import *", "module.py": "def func(): ..."}, - extensions=load_extensions(extension), - ): - assert extension.records == ["called as on_wildcard_expansion"] - - class LoadEventsTest(Extension): # noqa: D101 def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: D107 super().__init__()