From 86d321ed1303f7bde28950f14ea75412be1d6888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 15 Aug 2024 17:21:03 +0200 Subject: [PATCH] refactor: Remove all legacy code for v1 PR-314: https://github.com/mkdocstrings/griffe/pull/314 --- CHANGELOG.md | 7 +- config/pytest.ini | 4 - docs/guide/users/navigating.md | 6 +- docs/reference/api/deprecated.md | 172 ---------------- docs/reference/api/docstrings/parsers.md | 2 - docs/reference/api/extensions.md | 13 +- docs/reference/api/loggers.md | 11 +- docs/schema.json | 4 +- mkdocs.yml | 1 - pyproject.toml | 3 +- src/_griffe/agents/inspector.py | 26 +-- src/_griffe/agents/nodes/docstrings.py | 7 - src/_griffe/agents/nodes/exports.py | 11 +- src/_griffe/agents/nodes/runtime.py | 10 +- src/_griffe/agents/nodes/values.py | 11 +- src/_griffe/agents/visitor.py | 10 +- src/_griffe/cli.py | 36 ++-- src/_griffe/diff.py | 14 +- src/_griffe/docstrings/google.py | 71 +++++-- src/_griffe/docstrings/numpy.py | 46 ++--- src/_griffe/docstrings/sphinx.py | 31 ++- src/_griffe/docstrings/utils.py | 63 +----- src/_griffe/encoders.py | 21 +- src/_griffe/enumerations.py | 18 -- src/_griffe/expressions.py | 13 +- src/_griffe/extensions/base.py | 240 ++--------------------- src/_griffe/extensions/hybrid.py | 94 --------- src/_griffe/finder.py | 9 +- src/_griffe/importer.py | 2 +- src/_griffe/loader.py | 107 +++------- src/_griffe/logger.py | 83 ++++---- src/_griffe/merger.py | 13 +- src/_griffe/mixins.py | 26 +-- src/_griffe/models.py | 52 +---- src/griffe/__init__.py | 35 +--- src/griffe/agents/__init__.py | 17 -- src/griffe/agents/inspector.py | 17 -- src/griffe/agents/nodes.py | 24 --- src/griffe/agents/visitor.py | 17 -- src/griffe/c3linear.py | 17 -- src/griffe/cli.py | 17 -- src/griffe/collections.py | 17 -- src/griffe/dataclasses.py | 17 -- src/griffe/diff.py | 17 -- src/griffe/docstrings/__init__.py | 17 -- src/griffe/docstrings/dataclasses.py | 17 -- src/griffe/docstrings/google.py | 24 --- src/griffe/docstrings/numpy.py | 24 --- src/griffe/docstrings/parsers.py | 17 -- src/griffe/docstrings/sphinx.py | 24 --- src/griffe/docstrings/utils.py | 38 ---- src/griffe/encoders.py | 17 -- src/griffe/enumerations.py | 17 -- src/griffe/exceptions.py | 17 -- src/griffe/expressions.py | 17 -- src/griffe/extensions/__init__.py | 17 -- src/griffe/extensions/base.py | 17 -- src/griffe/extensions/dataclasses.py | 17 -- src/griffe/extensions/hybrid.py | 17 -- src/griffe/finder.py | 17 -- src/griffe/git.py | 17 -- src/griffe/importer.py | 17 -- src/griffe/loader.py | 17 -- src/griffe/logger.py | 17 -- src/griffe/merger.py | 17 -- src/griffe/mixins.py | 17 -- src/griffe/stats.py | 24 --- src/griffe/tests.py | 17 -- tests/test_cli.py | 1 + tests/test_docstrings/conftest.py | 8 +- tests/test_docstrings/helpers.py | 8 +- tests/test_finder.py | 2 +- tests/test_git.py | 2 +- tests/test_internals.py | 7 +- 74 files changed, 246 insertions(+), 1671 deletions(-) delete mode 100644 docs/reference/api/deprecated.md delete mode 100644 src/griffe/agents/__init__.py delete mode 100644 src/griffe/agents/inspector.py delete mode 100644 src/griffe/agents/nodes.py delete mode 100644 src/griffe/agents/visitor.py delete mode 100644 src/griffe/c3linear.py delete mode 100644 src/griffe/cli.py delete mode 100644 src/griffe/collections.py delete mode 100644 src/griffe/dataclasses.py delete mode 100644 src/griffe/diff.py delete mode 100644 src/griffe/docstrings/__init__.py delete mode 100644 src/griffe/docstrings/dataclasses.py delete mode 100644 src/griffe/docstrings/google.py delete mode 100644 src/griffe/docstrings/numpy.py delete mode 100644 src/griffe/docstrings/parsers.py delete mode 100644 src/griffe/docstrings/sphinx.py delete mode 100644 src/griffe/docstrings/utils.py delete mode 100644 src/griffe/encoders.py delete mode 100644 src/griffe/enumerations.py delete mode 100644 src/griffe/exceptions.py delete mode 100644 src/griffe/expressions.py delete mode 100644 src/griffe/extensions/__init__.py delete mode 100644 src/griffe/extensions/base.py delete mode 100644 src/griffe/extensions/dataclasses.py delete mode 100644 src/griffe/extensions/hybrid.py delete mode 100644 src/griffe/finder.py delete mode 100644 src/griffe/git.py delete mode 100644 src/griffe/importer.py delete mode 100644 src/griffe/loader.py delete mode 100644 src/griffe/logger.py delete mode 100644 src/griffe/merger.py delete mode 100644 src/griffe/mixins.py delete mode 100644 src/griffe/stats.py delete mode 100644 src/griffe/tests.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c1cfd2f2..f6821099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -619,11 +619,10 @@ We are still in v0, so no major bump yet. ### Deprecations -- Classes [`InspectorExtension`][griffe.InspectorExtension] - and [`VisitorExtension`][griffe.VisitorExtension] +- Classes `InspectorExtension` and `VisitorExtension` are deprecated in favor of [`Extension`][griffe.Extension]. - As a side-effect, the [`hybrid`][griffe.HybridExtension] extension - is also deprecated. See [how to use and write extensions](guide/users/extending.md). + As a side-effect, the `hybrid` extension is also deprecated. + See [how to use and write extensions](guide/users/extending.md). ### Breaking Changes diff --git a/config/pytest.ini b/config/pytest.ini index 5c9631bf..2b36076c 100644 --- a/config/pytest.ini +++ b/config/pytest.ini @@ -13,7 +13,3 @@ filterwarnings = # TODO: remove once pytest-xdist 4 is released ignore:.*rsyncdir:DeprecationWarning:xdist ignore:.*slated for removal in Python:DeprecationWarning:.* - # YORE: Bump 1: Remove line. - ignore:.*`get_logger`:DeprecationWarning:_griffe - # YORE: Bump 1: Remove line. - ignore:.*`name`:DeprecationWarning:_griffe diff --git a/docs/guide/users/navigating.md b/docs/guide/users/navigating.md index 3e8b5eeb..59d36424 100644 --- a/docs/guide/users/navigating.md +++ b/docs/guide/users/navigating.md @@ -375,8 +375,6 @@ Models have most fields in common, but also have specific fields. ### Functions - [`decorators`][griffe.Function.decorators]: The [decorators][griffe.Decorator] applied to the function. -- [`deleter`][griffe.Function.deleter]: The property deleter, if the function is a property. -- [`setter`][griffe.Function.setter]: The property setter, if the function is a property. - [`overloads`][griffe.Function.overloads]: The overloaded signatures of the function. - [`parameters`][griffe.Function.parameters]: The [parameters][griffe.Parameters] of the function. - [`returns`][griffe.Function.returns]: The type annotation of the returned value, in the form of an [expression][griffe.Expr]. The `annotation` field can also be used, for compatibility with attributes. @@ -385,6 +383,8 @@ Models have most fields in common, but also have specific fields. - [`annotation`][griffe.Attribute.annotation]: The type annotation of the attribute, in the form of an [expression][griffe.Expr]. - [`value`][griffe.Attribute.value]: The value of the attribute, in the form of an [expression][griffe.Expr]. +- [`deleter`][griffe.Attribute.deleter]: The property deleter. +- [`setter`][griffe.Attribute.setter]: The property setter. ### Alias @@ -434,7 +434,7 @@ Ultimately, these expressions are what allow downstream tools such as [mkdocstri During static analysis, these expressions also allow to analyze decorators, dataclass fields, and many more things in great details, and in a robust manner, to build third-party libraries support in the form of [Griffe extensions](extending.md). -To learn more about expressions, read their [API reference][griffe.expressions]. +To learn more about expressions, read their [API reference](../../reference/api/expressions.md). ### Modernization diff --git a/docs/reference/api/deprecated.md b/docs/reference/api/deprecated.md deleted file mode 100644 index 806efc93..00000000 --- a/docs/reference/api/deprecated.md +++ /dev/null @@ -1,172 +0,0 @@ -# Deprecated API - - - -Previously, Griffe exposed its [module layout][module-layout]. Before v1, it started hiding the module layout to expose the whole public API from the top-level [`griffe`][griffe] module. - -All the following submodules are deprecated, and all the objects they used to expose can now be imported or accessed from `griffe` directly. - -::: griffe.agents - options: - members: false - show_root_full_path: true - -::: griffe.agents.inspector - options: - members: false - show_root_full_path: true - -::: griffe.agents.nodes - options: - members: false - show_root_full_path: true - -::: griffe.agents.visitor - options: - members: false - show_root_full_path: true - -::: griffe.c3linear - options: - members: false - show_root_full_path: true - -::: griffe.cli - options: - members: false - show_root_full_path: true - -::: griffe.collections - options: - members: false - show_root_full_path: true - -::: griffe.dataclasses - options: - members: false - show_root_full_path: true - -::: griffe.diff - options: - members: false - show_root_full_path: true - -::: griffe.docstrings - options: - members: false - show_root_full_path: true - -::: griffe.docstrings.dataclasses - options: - members: false - show_root_full_path: true - -::: griffe.docstrings.google - options: - members: false - show_root_full_path: true - -::: griffe.docstrings.numpy - options: - members: false - show_root_full_path: true - -::: griffe.docstrings.parsers - options: - members: false - show_root_full_path: true - -::: griffe.docstrings.sphinx - options: - members: false - show_root_full_path: true - -::: griffe.docstrings.utils - options: - members: false - show_root_full_path: true - -::: griffe.encoders - options: - members: false - show_root_full_path: true - -::: griffe.enumerations - options: - members: false - show_root_full_path: true - -::: griffe.exceptions - options: - members: false - show_root_full_path: true - -::: griffe.expressions - options: - members: false - show_root_full_path: true - -::: griffe.extensions - options: - members: false - show_root_full_path: true - -::: griffe.extensions.base - options: - members: false - show_root_full_path: true - -::: griffe.extensions.dataclasses - options: - members: false - show_root_full_path: true - -::: griffe.extensions.hybrid - options: - members: false - show_root_full_path: true - -::: griffe.finder - options: - members: false - show_root_full_path: true - -::: griffe.git - options: - members: false - show_root_full_path: true - -::: griffe.importer - options: - members: false - show_root_full_path: true - -::: griffe.loader - options: - members: false - show_root_full_path: true - -::: griffe.logger - options: - members: false - show_root_full_path: true - -::: griffe.merger - options: - members: false - show_root_full_path: true - -::: griffe.mixins - options: - members: false - show_root_full_path: true - -::: griffe.stats - options: - members: false - show_root_full_path: true - -::: griffe.tests - options: - members: false - show_root_full_path: true diff --git a/docs/reference/api/docstrings/parsers.md b/docs/reference/api/docstrings/parsers.md index 10166ad2..72929942 100644 --- a/docs/reference/api/docstrings/parsers.md +++ b/docs/reference/api/docstrings/parsers.md @@ -24,8 +24,6 @@ ::: griffe.docstring_warning -::: griffe.DocstringWarningCallable - ::: griffe.DocstringDetectionMethod ::: griffe.infer_docstring_style \ No newline at end of file diff --git a/docs/reference/api/extensions.md b/docs/reference/api/extensions.md index 6f24b3e0..16b226dc 100644 --- a/docs/reference/api/extensions.md +++ b/docs/reference/api/extensions.md @@ -12,8 +12,6 @@ ## **Types** -::: griffe.ExtensionType - ::: griffe.LoadableExtensionType ## **Builtin extensions** @@ -21,14 +19,5 @@ ::: griffe.builtin_extensions ::: griffe.DataclassesExtension + options: inherited_members: false - -## **Deprecated API** - -::: griffe.When - -::: griffe.VisitorExtension - -::: griffe.InspectorExtension - -::: griffe.HybridExtension \ No newline at end of file diff --git a/docs/reference/api/loggers.md b/docs/reference/api/loggers.md index 97ddde04..0ba1d0db 100644 --- a/docs/reference/api/loggers.md +++ b/docs/reference/api/loggers.md @@ -2,8 +2,9 @@ ## **Main API** - - +::: griffe.logger + +::: griffe.get_logger ::: griffe.Logger @@ -15,10 +16,4 @@ ## **Advanced API** -::: griffe.patch_logger - -## **Deprecated API** - -::: griffe.get_logger - ::: griffe.patch_loggers diff --git a/docs/schema.json b/docs/schema.json index 666c11ad..cdbcfd60 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -160,8 +160,8 @@ ] }, "members": { - "type": "array", - "items": { + "type": "object", + "additionalProperties": { "$ref": "#" } }, diff --git a/mkdocs.yml b/mkdocs.yml index 295d91c2..7dbd43bf 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -82,7 +82,6 @@ nav: - Git utilities: reference/api/git.md - Loggers: reference/api/loggers.md - Helpers: reference/api/helpers.md - - Deprecated: reference/api/deprecated.md - Changelog: changelog.md - Insiders: - insiders/index.md diff --git a/pyproject.toml b/pyproject.toml index 9bef70f6..d941f010 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,8 +13,7 @@ requires-python = ">=3.8" keywords = ["api", "signature", "breaking-changes", "static-analysis", "dynamic-analysis"] dynamic = ["version"] classifiers = [ - # YORE: Bump 1: Replace `4 - Beta` with `5 - Production/Stable` within line. - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python", "Programming Language :: Python :: 3", diff --git a/src/_griffe/agents/inspector.py b/src/_griffe/agents/inspector.py index db6483ef..afd3c30f 100644 --- a/src/_griffe/agents/inspector.py +++ b/src/_griffe/agents/inspector.py @@ -15,10 +15,7 @@ from _griffe.expressions import safe_get_annotation from _griffe.extensions.base import Extensions, load_extensions from _griffe.importer import dynamic_import - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger from _griffe.models import Alias, Attribute, Class, Docstring, Function, Module, Parameter, Parameters if TYPE_CHECKING: @@ -28,8 +25,6 @@ from _griffe.expressions import Expr -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.agents.inspector") _empty = Signature.empty @@ -132,7 +127,7 @@ def __init__( self.filepath: Path | None = filepath """The module file path.""" - self.extensions: Extensions = extensions.attach_inspector(self) + self.extensions: Extensions = extensions """The extensions to use when inspecting.""" self.parent: Module | None = parent @@ -239,11 +234,7 @@ def inspect(self, node: ObjectNode) -> None: Parameters: node: The node to inspect. """ - for before_inspector in self.extensions.before_inspection: - before_inspector.inspect(node) getattr(self, f"inspect_{node.kind}", self.generic_inspect)(node) - for after_inspector in self.extensions.after_inspection: - after_inspector.inspect(node) def generic_inspect(self, node: ObjectNode) -> None: """Extend the base generic inspection with extensions. @@ -251,9 +242,6 @@ def generic_inspect(self, node: ObjectNode) -> None: Parameters: node: The node to inspect. """ - for before_inspector in self.extensions.before_children_inspection: - before_inspector.inspect(node) - for child in node.children: if target_path := child.alias_target_path: # If the child is an actual submodule of the current module, @@ -264,7 +252,7 @@ def generic_inspect(self, node: ObjectNode) -> None: # so we skip it here (no member, no alias, just skip it). if child.is_module and target_path == f"{self.current.path}.{child.name}": if not hasattr(child.obj, "__file__"): - _logger.debug(f"Module {target_path} is not discoverable on disk, inspecting right now") + logger.debug(f"Module {target_path} is not discoverable on disk, inspecting right now") inspector = Inspector( child.name, filepath=None, @@ -275,10 +263,7 @@ def generic_inspect(self, node: ObjectNode) -> None: lines_collection=self.lines_collection, modules_collection=self.modules_collection, ) - try: - inspector.inspect_module(child) - finally: - self.extensions.attach_inspector(self) + inspector.inspect_module(child) self.current.set_member(child.name, inspector.current.module) # Otherwise, alias the object. else: @@ -286,9 +271,6 @@ def generic_inspect(self, node: ObjectNode) -> None: else: self.inspect(child) - for after_inspector in self.extensions.after_children_inspection: - after_inspector.inspect(node) - def inspect_module(self, node: ObjectNode) -> None: """Inspect a module. diff --git a/src/_griffe/agents/nodes/docstrings.py b/src/_griffe/agents/nodes/docstrings.py index 03302d20..be448a9a 100644 --- a/src/_griffe/agents/nodes/docstrings.py +++ b/src/_griffe/agents/nodes/docstrings.py @@ -4,13 +4,6 @@ import ast -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger - -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.agents.nodes._docstrings") - def get_docstring( node: ast.AST, diff --git a/src/_griffe/agents/nodes/exports.py b/src/_griffe/agents/nodes/exports.py index 3af0b5d9..4961cbc2 100644 --- a/src/_griffe/agents/nodes/exports.py +++ b/src/_griffe/agents/nodes/exports.py @@ -9,19 +9,12 @@ from _griffe.agents.nodes.values import get_value from _griffe.enumerations import LogLevel - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger if TYPE_CHECKING: from _griffe.models import Module -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.agents.nodes._all") - - @dataclass class ExportedName: """An intermediate class to store names.""" @@ -112,5 +105,5 @@ def safe_get__all__( message += f": unsupported node {error}" else: message += f": {error}" - getattr(_logger, log_level.value)(message) + getattr(logger, log_level.value)(message) return [] diff --git a/src/_griffe/agents/nodes/runtime.py b/src/_griffe/agents/nodes/runtime.py index b07611d6..512299f9 100644 --- a/src/_griffe/agents/nodes/runtime.py +++ b/src/_griffe/agents/nodes/runtime.py @@ -8,13 +8,7 @@ from typing import Any, ClassVar, Sequence from _griffe.enumerations import ObjectKind - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger - -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.agents.nodes._runtime") +from _griffe.logger import logger _builtin_module_names = {_.lstrip("_") for _ in sys.builtin_module_names} _cyclic_relationships = { @@ -57,7 +51,7 @@ def __init__(self, obj: Any, name: str, parent: ObjectNode | None = None) -> Non # which triggers the __getattr__ method of the object, which in # turn can raise various exceptions. Probably not just __getattr__. # See https://github.com/pawamoy/pytkdocs/issues/45 - _logger.debug(f"Could not unwrap {name}: {error!r}") + logger.debug(f"Could not unwrap {name}: {error!r}") # Unwrap cached properties (`inspect.unwrap` doesn't do that). if isinstance(obj, cached_property): diff --git a/src/_griffe/agents/nodes/values.py b/src/_griffe/agents/nodes/values.py index 268c458a..bd463519 100644 --- a/src/_griffe/agents/nodes/values.py +++ b/src/_griffe/agents/nodes/values.py @@ -6,9 +6,7 @@ import sys from typing import TYPE_CHECKING -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger # YORE: EOL 3.8: Replace block with line 4. if sys.version_info < (3, 9): @@ -19,9 +17,6 @@ if TYPE_CHECKING: from pathlib import Path -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.agents.nodes._values") - def get_value(node: ast.AST | None) -> str | None: """Get the string representation of a node. @@ -49,10 +44,10 @@ def safe_get_value(node: ast.AST | None, filepath: str | Path | None = None) -> """ try: return get_value(node) - except Exception as error: + except Exception as error: # noqa: BLE001 message = f"Failed to represent node {node}" if filepath: message += f" at {filepath}:{node.lineno}" # type: ignore[union-attr] message += f": {error}" - _logger.exception(message) + logger.exception(message) return None diff --git a/src/_griffe/agents/visitor.py b/src/_griffe/agents/visitor.py index 8f57ed9d..9e3cc500 100644 --- a/src/_griffe/agents/visitor.py +++ b/src/_griffe/agents/visitor.py @@ -154,7 +154,7 @@ def __init__( self.code: str = code """The module source code.""" - self.extensions: Extensions = extensions.attach_visitor(self) + self.extensions: Extensions = extensions """The extensions to use when visiting the AST.""" self.parent: Module | None = parent @@ -210,11 +210,7 @@ def visit(self, node: ast.AST) -> None: Parameters: node: The node to visit. """ - for before_visitor in self.extensions.before_visit: - before_visitor.visit(node) getattr(self, f"visit_{ast_kind(node)}", self.generic_visit)(node) - for after_visitor in self.extensions.after_visit: - after_visitor.visit(node) def generic_visit(self, node: ast.AST) -> None: """Extend the base generic visit with extensions. @@ -222,12 +218,8 @@ def generic_visit(self, node: ast.AST) -> None: Parameters: node: The node to visit. """ - for before_visitor in self.extensions.before_children_visit: - before_visitor.visit(node) for child in ast_children(node): self.visit(child) - for after_visitor in self.extensions.after_children_visit: - after_visitor.visit(node) def visit_module(self, node: ast.Module) -> None: """Visit a module node. diff --git a/src/_griffe/cli.py b/src/_griffe/cli.py index b2071278..18b455fa 100644 --- a/src/_griffe/cli.py +++ b/src/_griffe/cli.py @@ -31,13 +31,10 @@ from _griffe.extensions.base import load_extensions from _griffe.git import get_latest_tag, get_repo_root from _griffe.loader import GriffeLoader, load, load_git - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger if TYPE_CHECKING: - from _griffe.extensions.base import Extensions, ExtensionType + from _griffe.extensions.base import Extension, Extensions DEFAULT_LOG_LEVEL = os.getenv("GRIFFE_LOG_LEVEL", "INFO").upper() @@ -46,9 +43,6 @@ This can be overridden by the `GRIFFE_LOG_LEVEL` environment variable. """ -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.cli") - class _DebugInfo(argparse.Action): def __init__(self, nargs: int | str | None = 0, **kwargs: Any) -> None: @@ -98,25 +92,25 @@ def _load_packages( # Load each package. for package in packages: if not package: - _logger.debug("Empty package name, continuing") + logger.debug("Empty package name, continuing") continue - _logger.info(f"Loading package {package}") + logger.info(f"Loading package {package}") try: loader.load(package, try_relative_path=True, find_stubs_package=find_stubs_package) except ModuleNotFoundError as error: - _logger.error(f"Could not find package {package}: {error}") # noqa: TRY400 + logger.error(f"Could not find package {package}: {error}") except ImportError as error: - _logger.exception(f"Tried but could not import package {package}: {error}") # noqa: TRY401 - _logger.info("Finished loading packages") + logger.exception(f"Tried but could not import package {package}: {error}") + logger.info("Finished loading packages") # Resolve aliases. if resolve_aliases: - _logger.info("Starting alias resolution") + logger.info("Starting alias resolution") unresolved, iterations = loader.resolve_aliases(implicit=resolve_implicit, external=resolve_external) if unresolved: - _logger.info(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations") + logger.info(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations") else: - _logger.info(f"All aliases were resolved after {iterations} iterations") + logger.info(f"All aliases were resolved after {iterations} iterations") return loader @@ -338,7 +332,7 @@ def dump( full: bool = False, docstring_parser: Parser | None = None, docstring_options: dict[str, Any] | None = None, - extensions: Sequence[str | dict[str, Any] | ExtensionType | type[ExtensionType]] | None = None, + extensions: Sequence[str | dict[str, Any] | Extension | type[Extension]] | None = None, resolve_aliases: bool = False, resolve_implicit: bool = False, resolve_external: bool | None = None, @@ -386,7 +380,7 @@ def dump( try: loaded_extensions = load_extensions(*(extensions or ())) except ExtensionError as error: - _logger.exception(str(error)) # noqa: TRY401 + logger.exception(str(error)) return 1 # Load packages. @@ -420,7 +414,7 @@ def dump( if stats: loader_stats = loader.stats() loader_stats.time_spent_serializing = elapsed.microseconds - _logger.info(loader_stats.as_text()) + logger.info(loader_stats.as_text()) return 0 if len(data_packages) == len(packages) else 1 @@ -431,7 +425,7 @@ def check( against_path: str | Path | None = None, *, base_ref: str | None = None, - extensions: Sequence[str | dict[str, Any] | ExtensionType | type[ExtensionType]] | None = None, + extensions: Sequence[str | dict[str, Any] | Extension | type[Extension]] | None = None, search_paths: Sequence[str | Path] | None = None, append_sys_path: bool = False, find_stubs_package: bool = False, @@ -474,7 +468,7 @@ def check( try: loaded_extensions = load_extensions(*(extensions or ())) except ExtensionError as error: - _logger.exception(str(error)) # noqa: TRY401 + logger.exception(str(error)) return 1 # Load old and new version of the package. diff --git a/src/_griffe/diff.py b/src/_griffe/diff.py index 49634417..9254bd35 100644 --- a/src/_griffe/diff.py +++ b/src/_griffe/diff.py @@ -18,10 +18,7 @@ from _griffe.enumerations import BreakageKind, ExplanationStyle, ParameterKind from _griffe.exceptions import AliasResolutionError from _griffe.git import _WORKTREE_PREFIX - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger if TYPE_CHECKING: from _griffe.models import Alias, Attribute, Class, Function, Object @@ -31,9 +28,6 @@ _POSITIONAL_KEYWORD_ONLY = frozenset((ParameterKind.positional_only, ParameterKind.keyword_only)) _VARIADIC = frozenset((ParameterKind.var_positional, ParameterKind.var_keyword)) -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.diff") - class Breakage: """Breakages can explain what broke from a version to another.""" @@ -460,7 +454,7 @@ def _alias_incompatibilities( old_member = old_obj.target if old_obj.is_alias else old_obj # type: ignore[union-attr] new_member = new_obj.target if new_obj.is_alias else new_obj # type: ignore[union-attr] except AliasResolutionError: - _logger.debug(f"API check: {old_obj.path} | {new_obj.path}: skip alias with unknown target") + logger.debug(f"API check: {old_obj.path} | {new_obj.path}: skip alias with unknown target") return yield from _type_based_yield(old_member, new_member, seen_paths=seen_paths) @@ -475,9 +469,9 @@ def _member_incompatibilities( seen_paths = set() if seen_paths is None else seen_paths for name, old_member in old_obj.all_members.items(): if not old_member.is_public: - _logger.debug(f"API check: {old_obj.path}.{name}: skip non-public object") + logger.debug(f"API check: {old_obj.path}.{name}: skip non-public object") continue - _logger.debug(f"API check: {old_obj.path}.{name}") + logger.debug(f"API check: {old_obj.path}.{name}") try: new_member = new_obj.all_members[name] except KeyError: diff --git a/src/_griffe/docstrings/google.py b/src/_griffe/docstrings/google.py index 9fec8040..61eb1e0d 100644 --- a/src/_griffe/docstrings/google.py +++ b/src/_griffe/docstrings/google.py @@ -44,9 +44,6 @@ from _griffe.expressions import Expr from _griffe.models import Docstring -# YORE: Bump 1: Regex-replace `\b_warn\b` with `docstring_warning` within file. -# YORE: Bump 1: Remove line. -_warn = docstring_warning("griffe.docstrings.google") _section_kind = { "args": DocstringSectionKind.parameters, @@ -123,7 +120,7 @@ def _read_block_items(docstring: Docstring, *, offset: int, **options: Any) -> _ # indent between initial and continuation: append but warn cont_indent = len(line) - len(line.lstrip()) current_item[1].append(line[cont_indent:]) - _warn( + docstring_warning( docstring, new_offset, f"Confusing indentation for continuation line {new_offset+1} in docstring, " @@ -195,7 +192,7 @@ def _read_parameters( try: name_with_type, description = param_lines[0].split(":", 1) except ValueError: - _warn(docstring, line_number, f"Failed to get 'name: description' pair from '{param_lines[0]}'") + docstring_warning(docstring, line_number, f"Failed to get 'name: description' pair from '{param_lines[0]}'") continue description = "\n".join([description.lstrip(), *param_lines[1:]]).rstrip("\n") @@ -222,7 +219,7 @@ def _read_parameters( default = None if annotation is None: - _warn(docstring, line_number, f"No type or annotation for parameter '{name}'") + docstring_warning(docstring, line_number, f"No type or annotation for parameter '{name}'") if warn_unknown_params: with suppress(AttributeError): # for parameters sections in objects without parameters @@ -233,7 +230,7 @@ def _read_parameters( if starred_name in params: message += f". Did you mean '{starred_name}'?" break - _warn(docstring, line_number, message) + docstring_warning(docstring, line_number, message) parameters.append(DocstringParameter(name=name, value=default, annotation=annotation, description=description)) @@ -275,7 +272,7 @@ def _read_attributes_section( try: name_with_type, description = attr_lines[0].split(":", 1) except ValueError: - _warn(docstring, line_number, f"Failed to get 'name: description' pair from '{attr_lines[0]}'") + docstring_warning(docstring, line_number, f"Failed to get 'name: description' pair from '{attr_lines[0]}'") continue description = "\n".join([description.lstrip(), *attr_lines[1:]]).rstrip("\n") @@ -311,7 +308,11 @@ def _read_functions_section( try: name_with_signature, description = func_lines[0].split(":", 1) except ValueError: - _warn(docstring, line_number, f"Failed to get 'signature: description' pair from '{func_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get 'signature: description' pair from '{func_lines[0]}'", + ) continue description = "\n".join([description.lstrip(), *func_lines[1:]]).rstrip("\n") @@ -342,7 +343,11 @@ def _read_classes_section( try: name_with_signature, description = class_lines[0].split(":", 1) except ValueError: - _warn(docstring, line_number, f"Failed to get 'signature: description' pair from '{class_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get 'signature: description' pair from '{class_lines[0]}'", + ) continue description = "\n".join([description.lstrip(), *class_lines[1:]]).rstrip("\n") @@ -372,7 +377,11 @@ def _read_modules_section( try: name, description = module_lines[0].split(":", 1) except ValueError: - _warn(docstring, line_number, f"Failed to get 'name: description' pair from '{module_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get 'name: description' pair from '{module_lines[0]}'", + ) continue description = "\n".join([description.lstrip(), *module_lines[1:]]).rstrip("\n") modules.append(DocstringModule(name=name, description=description)) @@ -394,7 +403,11 @@ def _read_raises_section( try: annotation, description = exception_lines[0].split(":", 1) except ValueError: - _warn(docstring, line_number, f"Failed to get 'exception: description' pair from '{exception_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get 'exception: description' pair from '{exception_lines[0]}'", + ) else: description = "\n".join([description.lstrip(), *exception_lines[1:]]).rstrip("\n") # try to compile the annotation to transform it into an expression @@ -417,7 +430,11 @@ def _read_warns_section( try: annotation, description = warning_lines[0].split(":", 1) except ValueError: - _warn(docstring, line_number, f"Failed to get 'warning: description' pair from '{warning_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get 'warning: description' pair from '{warning_lines[0]}'", + ) else: description = "\n".join([description.lstrip(), *warning_lines[1:]]).rstrip("\n") warns.append(DocstringWarn(annotation=annotation, description=description)) @@ -445,7 +462,11 @@ def _read_returns_section( if returns_named_value: match = _RE_NAME_ANNOTATION_DESCRIPTION.match(return_lines[0]) if not match: - _warn(docstring, line_number, f"Failed to get name, annotation or description from '{return_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get name, annotation or description from '{return_lines[0]}'", + ) continue name, annotation, description = match.groups() else: @@ -489,7 +510,7 @@ def _read_returns_section( if annotation is None: returned_value = repr(name) if name else index + 1 - _warn(docstring, line_number, f"No type or annotation for returned value {returned_value}") + docstring_warning(docstring, line_number, f"No type or annotation for returned value {returned_value}") returns.append(DocstringReturn(name=name or "", annotation=annotation, description=description)) @@ -508,7 +529,11 @@ def _read_yields_section( for index, (line_number, yield_lines) in enumerate(block): match = _RE_NAME_ANNOTATION_DESCRIPTION.match(yield_lines[0]) if not match: - _warn(docstring, line_number, f"Failed to get name, annotation or description from '{yield_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get name, annotation or description from '{yield_lines[0]}'", + ) continue name, annotation, description = match.groups() @@ -536,7 +561,7 @@ def _read_yields_section( if annotation is None: yielded_value = repr(name) if name else index + 1 - _warn(docstring, line_number, f"No type or annotation for yielded value {yielded_value}") + docstring_warning(docstring, line_number, f"No type or annotation for yielded value {yielded_value}") yields.append(DocstringYield(name=name or "", annotation=annotation, description=description)) @@ -555,7 +580,11 @@ def _read_receives_section( for index, (line_number, receive_lines) in enumerate(block): match = _RE_NAME_ANNOTATION_DESCRIPTION.match(receive_lines[0]) if not match: - _warn(docstring, line_number, f"Failed to get name, annotation or description from '{receive_lines[0]}'") + docstring_warning( + docstring, + line_number, + f"Failed to get name, annotation or description from '{receive_lines[0]}'", + ) continue name, annotation, description = match.groups() @@ -579,7 +608,7 @@ def _read_receives_section( if annotation is None: received_value = repr(name) if name else index + 1 - _warn(docstring, line_number, f"No type or annotation for received value {received_value}") + docstring_warning(docstring, line_number, f"No type or annotation for received value {received_value}") receives.append(DocstringReceive(name=name or "", annotation=annotation, description=description)) @@ -657,7 +686,7 @@ def _read_deprecated_section( try: version, text = text.split(":", 1) except ValueError: - _warn(docstring, new_offset, f"Could not parse version, text at line {offset}") + docstring_warning(docstring, new_offset, f"Could not parse version, text at line {offset}") return None, new_offset version = version.lstrip() @@ -791,7 +820,7 @@ def parse_google( reasons.append(f"Extraneous blank line below {kind} title") if reasons: reasons_string = "; ".join(reasons) - _warn( + docstring_warning( docstring, offset, f"Possible {kind} skipped, reasons: {reasons_string}", diff --git a/src/_griffe/docstrings/numpy.py b/src/_griffe/docstrings/numpy.py index 74ebd6a7..ed1f736f 100644 --- a/src/_griffe/docstrings/numpy.py +++ b/src/_griffe/docstrings/numpy.py @@ -63,10 +63,6 @@ from _griffe.models import Docstring -# YORE: Bump 1: Regex-replace `\b_warn\b` with `docstring_warning` within file. -# YORE: Bump 1: Remove line. -_warn = docstring_warning("griffe.docstrings.numpy") - _section_kind = { "deprecated": DocstringSectionKind.deprecated, "parameters": DocstringSectionKind.parameters, @@ -130,7 +126,7 @@ def _read_block_items( # indent between initial and continuation: append but warn cont_indent = len(line) - len(line.lstrip()) current_item.append(line[cont_indent:]) - _warn( + docstring_warning( docstring, new_offset, f"Confusing indentation for continuation line {new_offset+1} in docstring, " @@ -230,7 +226,7 @@ def _read_parameters( for item in items: match = _RE_PARAMETER.match(item[0]) if not match: - _warn(docstring, new_offset, f"Could not parse line '{item[0]}'") + docstring_warning(docstring, new_offset, f"Could not parse line '{item[0]}'") continue names = match.group("names").split(", ") @@ -256,7 +252,7 @@ def _read_parameters( annotation = docstring.parent.parameters[name].annotation # type: ignore[union-attr] break else: - _warn(docstring, new_offset, f"No types or annotations for parameters {names}") + docstring_warning(docstring, new_offset, f"No types or annotations for parameters {names}") else: annotation = parse_docstring_annotation(annotation, docstring, log_level=LogLevel.debug) @@ -276,7 +272,7 @@ def _read_parameters( if starred_name in params: message += f". Did you mean '{starred_name}'?" break - _warn(docstring, new_offset, message) + docstring_warning(docstring, new_offset, message) for name in names: parameters.append(DocstringParameter(name, value=default, annotation=annotation, description=description)) @@ -295,7 +291,7 @@ def _read_parameters_section( if parameters: return DocstringSectionParameters(parameters), new_offset - _warn(docstring, new_offset, f"Empty parameters section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty parameters section at line {offset}") return None, new_offset @@ -311,7 +307,7 @@ def _read_other_parameters_section( if parameters: return DocstringSectionOtherParameters(parameters), new_offset - _warn(docstring, new_offset, f"Empty other parameters section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty other parameters section at line {offset}") return None, new_offset @@ -327,11 +323,11 @@ def _read_deprecated_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty deprecated section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty deprecated section at line {offset}") return None, new_offset if len(items) > 1: - _warn(docstring, new_offset, f"Too many deprecated items at {offset}") + docstring_warning(docstring, new_offset, f"Too many deprecated items at {offset}") item = items[0] version = item[0] @@ -350,14 +346,14 @@ def _read_returns_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty returns section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty returns section at line {offset}") return None, new_offset returns = [] for index, item in enumerate(items): match = _RE_RETURNS.match(item[0]) if not match: - _warn(docstring, new_offset, f"Could not parse line '{item[0]}'") + docstring_warning(docstring, new_offset, f"Could not parse line '{item[0]}'") continue groups = match.groupdict() @@ -407,14 +403,14 @@ def _read_yields_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty yields section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty yields section at line {offset}") return None, new_offset yields = [] for index, item in enumerate(items): match = _RE_YIELDS.match(item[0]) if not match: - _warn(docstring, new_offset, f"Could not parse line '{item[0]}'") + docstring_warning(docstring, new_offset, f"Could not parse line '{item[0]}'") continue groups = match.groupdict() @@ -455,14 +451,14 @@ def _read_receives_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty receives section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty receives section at line {offset}") return None, new_offset receives = [] for index, item in enumerate(items): match = _RE_RECEIVES.match(item[0]) if not match: - _warn(docstring, new_offset, f"Could not parse line '{item[0]}'") + docstring_warning(docstring, new_offset, f"Could not parse line '{item[0]}'") continue groups = match.groupdict() @@ -499,7 +495,7 @@ def _read_raises_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty raises section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty raises section at line {offset}") return None, new_offset raises = [] @@ -522,7 +518,7 @@ def _read_warns_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty warns section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty warns section at line {offset}") return None, new_offset warns = [] @@ -545,7 +541,7 @@ def _read_attributes_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty attributes section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty attributes section at line {offset}") return None, new_offset annotation: str | Expr | None @@ -580,7 +576,7 @@ def _read_functions_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty functions/methods section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty functions/methods section at line {offset}") return None, new_offset functions = [] @@ -610,7 +606,7 @@ def _read_classes_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty classes section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty classes section at line {offset}") return None, new_offset classes = [] @@ -640,7 +636,7 @@ def _read_modules_section( items, new_offset = _read_block_items(docstring, offset=offset, **options) if not items: - _warn(docstring, new_offset, f"Empty modules section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty modules section at line {offset}") return None, new_offset modules = [] @@ -718,7 +714,7 @@ def _read_examples_section( if sub_sections: return DocstringSectionExamples(sub_sections), new_offset - _warn(docstring, new_offset, f"Empty examples section at line {offset}") + docstring_warning(docstring, new_offset, f"Empty examples section at line {offset}") return None, new_offset diff --git a/src/_griffe/docstrings/sphinx.py b/src/_griffe/docstrings/sphinx.py index 5e550406..72415052 100644 --- a/src/_griffe/docstrings/sphinx.py +++ b/src/_griffe/docstrings/sphinx.py @@ -28,9 +28,6 @@ from _griffe.expressions import Expr from _griffe.models import Docstring -# YORE: Bump 1: Regex-replace `\b_warn\b` with `docstring_warning` within file. -# YORE: Bump 1: Remove line. -_warn = docstring_warning("griffe.docstrings.sphinx") # TODO: Examples: from the documentation, we're not sure there is a standard format for examples _PARAM_NAMES = frozenset(("param", "parameter", "arg", "argument", "key", "keyword")) @@ -142,11 +139,11 @@ def _read_parameter( directive_type = parsed_directive.directive_parts[1] name = parsed_directive.directive_parts[2] else: - _warn(docstring, 0, f"Failed to parse field directive from '{parsed_directive.line}'") + docstring_warning(docstring, 0, f"Failed to parse field directive from '{parsed_directive.line}'") return parsed_directive.next_index if name in parsed_values.parameters: - _warn(docstring, 0, f"Duplicate parameter entry for '{name}'") + docstring_warning(docstring, 0, f"Duplicate parameter entry for '{name}'") return parsed_directive.next_index if warn_unknown_params: @@ -158,7 +155,7 @@ def _read_parameter( if starred_name in params: message += f". Did you mean '{starred_name}'?" break - _warn(docstring, 0, message) + docstring_warning(docstring, 0, message) annotation = _determine_param_annotation(docstring, name, directive_type, parsed_values) default = _determine_param_default(docstring, name) @@ -201,13 +198,13 @@ def _determine_param_annotation( annotation = directive_type if directive_type is not None and parsed_param_type is not None: - _warn(docstring, 0, f"Duplicate parameter information for '{name}'") + docstring_warning(docstring, 0, f"Duplicate parameter information for '{name}'") if annotation is None: try: annotation = docstring.parent.parameters[name.lstrip()].annotation # type: ignore[union-attr] except (AttributeError, KeyError): - _warn(docstring, 0, f"No matching parameter for '{name}'") + docstring_warning(docstring, 0, f"No matching parameter for '{name}'") return annotation @@ -226,7 +223,7 @@ def _read_parameter_type( if len(parsed_directive.directive_parts) == 2: # noqa: PLR2004 param_name = parsed_directive.directive_parts[1] else: - _warn(docstring, 0, f"Failed to get parameter name from '{parsed_directive.line}'") + docstring_warning(docstring, 0, f"Failed to get parameter name from '{parsed_directive.line}'") return parsed_directive.next_index parsed_values.param_types[param_name] = param_type @@ -235,7 +232,7 @@ def _read_parameter_type( if param.annotation is None: param.annotation = param_type else: - _warn(docstring, 0, f"Duplicate parameter information for '{param_name}'") + docstring_warning(docstring, 0, f"Duplicate parameter information for '{param_name}'") return parsed_directive.next_index @@ -252,7 +249,7 @@ def _read_attribute( if len(parsed_directive.directive_parts) == 2: # noqa: PLR2004 name = parsed_directive.directive_parts[1] else: - _warn(docstring, 0, f"Failed to parse field directive from '{parsed_directive.line}'") + docstring_warning(docstring, 0, f"Failed to parse field directive from '{parsed_directive.line}'") return parsed_directive.next_index annotation: str | Expr | None = None @@ -270,7 +267,7 @@ def _read_attribute( with suppress(AttributeError, KeyError): annotation = docstring.parent.attributes[name].annotation # type: ignore[union-attr] if name in parsed_values.attributes: - _warn(docstring, 0, f"Duplicate attribute entry for '{name}'") + docstring_warning(docstring, 0, f"Duplicate attribute entry for '{name}'") else: parsed_values.attributes[name] = DocstringAttribute( name=name, @@ -295,7 +292,7 @@ def _read_attribute_type( if len(parsed_directive.directive_parts) == 2: # noqa: PLR2004 attribute_name = parsed_directive.directive_parts[1] else: - _warn(docstring, 0, f"Failed to get attribute name from '{parsed_directive.line}'") + docstring_warning(docstring, 0, f"Failed to get attribute name from '{parsed_directive.line}'") return parsed_directive.next_index parsed_values.attribute_types[attribute_name] = attribute_type @@ -304,7 +301,7 @@ def _read_attribute_type( if attribute.annotation is None: attribute.annotation = attribute_type else: - _warn(docstring, 0, f"Duplicate attribute information for '{attribute_name}'") + docstring_warning(docstring, 0, f"Duplicate attribute information for '{attribute_name}'") return parsed_directive.next_index @@ -322,7 +319,7 @@ def _read_exception( ex_type = parsed_directive.directive_parts[1] parsed_values.exceptions.append(DocstringRaise(annotation=ex_type, description=parsed_directive.value)) else: - _warn(docstring, 0, f"Failed to parse exception directive from '{parsed_directive.line}'") + docstring_warning(docstring, 0, f"Failed to parse exception directive from '{parsed_directive.line}'") return parsed_directive.next_index @@ -343,7 +340,7 @@ def _read_return(docstring: Docstring, offset: int, parsed_values: _ParsedValues try: annotation = docstring.parent.annotation # type: ignore[union-attr] except AttributeError: - _warn(docstring, 0, f"No return type or annotation at '{parsed_directive.line}'") + docstring_warning(docstring, 0, f"No return type or annotation at '{parsed_directive.line}'") annotation = None # TODO: maybe support names @@ -392,7 +389,7 @@ def _parse_directive(docstring: Docstring, offset: int) -> _ParsedDirective: try: _, directive, value = line.split(":", 2) except ValueError: - _warn(docstring, 0, f"Failed to get ':directive: value' pair from '{line}'") + docstring_warning(docstring, 0, f"Failed to get ':directive: value' pair from '{line}'") return _ParsedDirective(line, next_index, [], "", invalid=True) value = value.strip() diff --git a/src/_griffe/docstrings/utils.py b/src/_griffe/docstrings/utils.py index b8e1c6ce..8070a319 100644 --- a/src/_griffe/docstrings/utils.py +++ b/src/_griffe/docstrings/utils.py @@ -2,75 +2,31 @@ from __future__ import annotations -import warnings from ast import PyCF_ONLY_AST from contextlib import suppress -from typing import TYPE_CHECKING, Protocol, overload +from typing import TYPE_CHECKING from _griffe.enumerations import LogLevel from _griffe.exceptions import BuiltinModuleError from _griffe.expressions import safe_get_annotation - -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger if TYPE_CHECKING: from _griffe.expressions import Expr from _griffe.models import Docstring -# YORE: Bump 1: Remove block. -class DocstringWarningCallable(Protocol): - """A callable that logs a warning message.""" - - def __call__(self, docstring: Docstring, offset: int, message: str, log_level: LogLevel = ...) -> None: - """Log a warning message. - - Parameters: - docstring: The docstring in which the warning occurred. - offset: The offset in the docstring lines. - message: The message to log. - log_level: The log level to use. - """ - - -# YORE: Bump 1: Remove line. -_sentinel = object() - - -# YORE: Bump 1: Remove block. -@overload -def docstring_warning(name: str) -> DocstringWarningCallable: ... - - -# YORE: Bump 1: Remove block. -@overload def docstring_warning( docstring: Docstring, offset: int, message: str, log_level: LogLevel = LogLevel.warning, -) -> None: ... - - -def docstring_warning( # type: ignore[misc] - # YORE: Bump 1: Remove line. - name: str | None = None, - # YORE: Bump 1: Replace line with `docstring: Docstring,`. - docstring: Docstring = _sentinel, # type: ignore[assignment] - # YORE: Bump 1: Replace line with `offset: int,`. - offset: int = _sentinel, # type: ignore[assignment] - # YORE: Bump 1: Replace line with `message: str,`. - message: str = _sentinel, # type: ignore[assignment] - log_level: LogLevel = LogLevel.warning, - # YORE: Bump 1: Replace line with `) -> None:`. -) -> DocstringWarningCallable | None: +) -> None: """Log a warning when parsing a docstring. This function logs a warning message by prefixing it with the filepath and line number. Parameters: - name: Deprecated. If passed, the function returns a callable, and other arguments are ignored. docstring: The docstring object. offset: The offset in the docstring lines. message: The message to log. @@ -78,15 +34,6 @@ def docstring_warning( # type: ignore[misc] Returns: A function used to log parsing warnings if `name` was passed, else none. """ - # YORE: Bump 1: Remove block. - if name is not None: - if not name.startswith("griffe."): - warnings.warn("The `name` parameter is deprecated.", DeprecationWarning, stacklevel=1) - logger = get_logger(name) - else: - if docstring is _sentinel or offset is _sentinel or message is _sentinel: - raise ValueError("Missing required arguments docstring/offset/message.") - logger = get_logger("griffe") def warn(docstring: Docstring, offset: int, message: str, log_level: LogLevel = LogLevel.warning) -> None: try: @@ -98,11 +45,7 @@ def warn(docstring: Docstring, offset: int, message: str, log_level: LogLevel = log = getattr(logger, log_level.value) log(f"{prefix}:{(docstring.lineno or 0)+offset}: {message}") - if name is not None: - return warn - warn(docstring, offset, message, log_level) - return None def parse_docstring_annotation( diff --git a/src/_griffe/encoders.py b/src/_griffe/encoders.py index c56a42d1..5cda844f 100644 --- a/src/_griffe/encoders.py +++ b/src/_griffe/encoders.py @@ -4,9 +4,8 @@ from __future__ import annotations import json -import warnings from pathlib import Path, PosixPath, WindowsPath -from typing import TYPE_CHECKING, Any, Callable +from typing import Any, Callable from _griffe import expressions from _griffe.enumerations import Kind, ParameterKind @@ -23,10 +22,6 @@ Parameters, ) -if TYPE_CHECKING: - from _griffe.enumerations import Parser - - _json_encoder_map: dict[type, Callable[[Any], Any]] = { Path: str, PosixPath: str, @@ -54,10 +49,6 @@ def __init__( self, *args: Any, full: bool = False, - # YORE: Bump 1: Remove line. - docstring_parser: Parser | None = None, - # YORE: Bump 1: Remove line. - docstring_options: dict[str, Any] | None = None, **kwargs: Any, ) -> None: """Initialize the encoder. @@ -76,16 +67,6 @@ def __init__( self.full: bool = full """Whether to dump full data or base data.""" - # YORE: Bump 1: Remove block. - self.docstring_parser: Parser | None = docstring_parser - """Deprecated. The docstring parser to use. By default, no parsing is done.""" - self.docstring_options: dict[str, Any] = docstring_options or {} - """Deprecated. Additional docstring parsing options.""" - if docstring_parser is not None: - warnings.warn("Parameter `docstring_parser` is deprecated and has no effect.", stacklevel=1) - if docstring_options is not None: - warnings.warn("Parameter `docstring_options` is deprecated and has no effect.", stacklevel=1) - def default(self, obj: Any) -> Any: """Return a serializable representation of the given object. diff --git a/src/_griffe/enumerations.py b/src/_griffe/enumerations.py index 1d5ce16e..df317ec1 100644 --- a/src/_griffe/enumerations.py +++ b/src/_griffe/enumerations.py @@ -180,21 +180,3 @@ class ObjectKind(str, Enum): def __str__(self) -> str: return self.value - - -# YORE: Bump 1: Remove block. -class When(int, Enum): - """Enumeration of the different times at which an extension is used. - - Deprecated. This enumeration is used with the `VisitorExtension` and `InspectorExtension` classes, - which are deprecated. Use the `Extension` class instead, which does not need `When`. - """ - - before_all: int = 1 - """For each node, before the visit/inspection.""" - before_children: int = 2 - """For each node, after the visit has started, and before the children visit/inspection.""" - after_children: int = 3 - """For each node, after the children have been visited/inspected, and before finishing the visit/inspection.""" - after_all: int = 4 - """For each node, after the visit/inspection.""" diff --git a/src/_griffe/expressions.py b/src/_griffe/expressions.py index c0f07d42..86614572 100644 --- a/src/_griffe/expressions.py +++ b/src/_griffe/expressions.py @@ -17,10 +17,7 @@ from _griffe.agents.nodes.parameters import get_parameters from _griffe.enumerations import LogLevel, ParameterKind from _griffe.exceptions import NameResolutionError - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger if TYPE_CHECKING: from pathlib import Path @@ -28,10 +25,6 @@ from _griffe.models import Class, Module -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.expressions") - - def _yield(element: str | Expr | tuple[str | Expr, ...], *, flat: bool = True) -> Iterator[str | Expr]: if isinstance(element, str): yield element @@ -976,7 +969,7 @@ def _build_constant( optimize=1, ) except SyntaxError: - _logger.debug( + logger.debug( f"Tried and failed to parse {node.value!r} as Python code, " "falling back to using it as a string literal " "(postponed annotations might help: https://peps.python.org/pep-0563/)", @@ -1256,7 +1249,7 @@ def safe_get_expression( lineno = node.lineno # type: ignore[union-attr] error_str = f"{error.__class__.__name__}: {error}" message = msg_format.format(path=path, lineno=lineno, node_class=node_class, error=error_str) - getattr(_logger, log_level.value)(message) + getattr(logger, log_level.value)(message) return None diff --git a/src/_griffe/extensions/base.py b/src/_griffe/extensions/base.py index c2319a70..54c20db8 100644 --- a/src/_griffe/extensions/base.py +++ b/src/_griffe/extensions/base.py @@ -5,15 +5,12 @@ import os import sys -import warnings -from collections import defaultdict from importlib.util import module_from_spec, spec_from_file_location -from inspect import isclass, signature +from inspect import isclass from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, Sequence, Type, Union +from typing import TYPE_CHECKING, Any, Dict, Type, Union from _griffe.agents.nodes.ast import ast_children, ast_kind -from _griffe.enumerations import When from _griffe.exceptions import ExtensionNotLoadedError from _griffe.importer import dynamic_import @@ -27,76 +24,6 @@ from _griffe.models import Attribute, Class, Function, Module, Object -# YORE: Bump 1: Remove block. -class VisitorExtension: - """Deprecated in favor of `Extension`. The node visitor extension base class, to inherit from.""" - - when: When = When.after_all - """When the visitor extension should run.""" - - def __init__(self) -> None: - """Initialize the visitor extension.""" - warnings.warn( - "Visitor extensions are deprecated in favor of the new, more developer-friendly Extension. " - "See https://mkdocstrings.github.io/griffe/extensions/", - DeprecationWarning, - stacklevel=1, - ) - self.visitor: Visitor = None # type: ignore[assignment] - """The parent visitor.""" - - def attach(self, visitor: Visitor) -> None: - """Attach the parent visitor to this extension. - - Parameters: - visitor: The parent visitor. - """ - self.visitor = visitor - - def visit(self, node: ast.AST) -> None: - """Visit a node. - - Parameters: - node: The node to visit. - """ - getattr(self, f"visit_{ast_kind(node)}", lambda _: None)(node) - - -# YORE: Bump 1: Remove block. -class InspectorExtension: - """Deprecated in favor of `Extension`. The object inspector extension base class, to inherit from.""" - - when: When = When.after_all - """When the inspector extension should run.""" - - def __init__(self) -> None: - """Initialize the inspector extension.""" - warnings.warn( - "Inspector extensions are deprecated in favor of the new, more developer-friendly Extension. " - "See https://mkdocstrings.github.io/griffe/extensions/", - DeprecationWarning, - stacklevel=1, - ) - self.inspector: Inspector = None # type: ignore[assignment] - """The parent inspector.""" - - def attach(self, inspector: Inspector) -> None: - """Attach the parent inspector to this extension. - - Parameters: - inspector: The parent inspector. - """ - self.inspector = inspector - - def inspect(self, node: ObjectNode) -> None: - """Inspect a node. - - Parameters: - node: The node to inspect. - """ - getattr(self, f"inspect_{node.kind}", lambda _: None)(node) - - class Extension: """Base class for Griffe extensions.""" @@ -291,125 +218,30 @@ def on_package_loaded(self, *, pkg: Module, **kwargs: Any) -> None: """ -# YORE: Bump 1: Remove block. -ExtensionType = Union[VisitorExtension, InspectorExtension, Extension] -"""All the types that can be passed to `Extensions.add`. Deprecated. Use `Extension` instead.""" - -# YORE: Bump 1: Regex-replace `\bExtensionType\b` with `Extension` within line. -LoadableExtensionType = Union[str, Dict[str, Any], ExtensionType, Type[ExtensionType]] +LoadableExtensionType = Union[str, Dict[str, Any], Extension, Type[Extension]] """All the types that can be passed to `load_extensions`.""" class Extensions: """This class helps iterating on extensions that should run at different times.""" - # YORE: Bump 1: Replace `ExtensionType` with `Extension` within line. - def __init__(self, *extensions: ExtensionType) -> None: + def __init__(self, *extensions: Extension) -> None: """Initialize the extensions container. Parameters: *extensions: The extensions to add. """ - # YORE: Bump 1: Remove block. - self._visitors: dict[When, list[VisitorExtension]] = defaultdict(list) - self._inspectors: dict[When, list[InspectorExtension]] = defaultdict(list) - self._extensions: list[Extension] = [] self.add(*extensions) - # YORE: Bump 1: Replace `ExtensionType` with `Extension` within line. - def add(self, *extensions: ExtensionType) -> None: + def add(self, *extensions: Extension) -> None: """Add extensions to this container. Parameters: *extensions: The extensions to add. """ for extension in extensions: - # YORE: Bump 1: Replace block with line 6 - if isinstance(extension, VisitorExtension): - self._visitors[extension.when].append(extension) - elif isinstance(extension, InspectorExtension): - self._inspectors[extension.when].append(extension) - else: - self._extensions.append(extension) - - # YORE: Bump 1: Remove block. - def attach_visitor(self, parent_visitor: Visitor) -> Extensions: - """Attach a parent visitor to the visitor extensions. - - Parameters: - parent_visitor: The parent visitor, leading the visit. - - Returns: - Self, conveniently. - """ - for when in self._visitors: - for visitor in self._visitors[when]: - visitor.attach(parent_visitor) - return self - - # YORE: Bump 1: Remove block. - def attach_inspector(self, parent_inspector: Inspector) -> Extensions: - """Attach a parent inspector to the inspector extensions. - - Parameters: - parent_inspector: The parent inspector, leading the inspection. - - Returns: - Self, conveniently. - """ - for when in self._inspectors: - for inspector in self._inspectors[when]: - inspector.attach(parent_inspector) - return self - - # YORE: Bump 1: Remove block. - @property - def before_visit(self) -> list[VisitorExtension]: - """The visitors that run before the visit.""" - return self._visitors[When.before_all] - - # YORE: Bump 1: Remove block. - @property - def before_children_visit(self) -> list[VisitorExtension]: - """The visitors that run before the children visit.""" - return self._visitors[When.before_children] - - # YORE: Bump 1: Remove block. - @property - def after_children_visit(self) -> list[VisitorExtension]: - """The visitors that run after the children visit.""" - return self._visitors[When.after_children] - - # YORE: Bump 1: Remove block. - @property - def after_visit(self) -> list[VisitorExtension]: - """The visitors that run after the visit.""" - return self._visitors[When.after_all] - - # YORE: Bump 1: Remove block. - @property - def before_inspection(self) -> list[InspectorExtension]: - """The inspectors that run before the inspection.""" - return self._inspectors[When.before_all] - - # YORE: Bump 1: Remove block. - @property - def before_children_inspection(self) -> list[InspectorExtension]: - """The inspectors that run before the children inspection.""" - return self._inspectors[When.before_children] - - # YORE: Bump 1: Remove block. - @property - def after_children_inspection(self) -> list[InspectorExtension]: - """The inspectors that run after the children inspection.""" - return self._inspectors[When.after_children] - - # YORE: Bump 1: Remove block. - @property - def after_inspection(self) -> list[InspectorExtension]: - """The inspectors that run after the inspection.""" - return self._inspectors[When.after_all] + self._extensions.append(extension) def call(self, event: str, **kwargs: Any) -> None: """Call the extension hook for the given event. @@ -419,25 +251,10 @@ def call(self, event: str, **kwargs: Any) -> None: **kwargs: Arguments passed to the hook. """ for extension in self._extensions: - # YORE: Bump 1: Replace block with `getattr(extension, event)(**kwargs)`. - hook = getattr(extension, event) - params = signature(hook).parameters - has_kwargs = any(p.kind is p.VAR_KEYWORD for p in params.values()) - if not has_kwargs: - warnings.warn( - f"{hook.__qualname__} must accept variadic keyword parameters " - "(**kwargs) to allow forward-compatibility.", - DeprecationWarning, - stacklevel=1, - ) - hook(**{k: v for k, v in kwargs.items() if k in params}) - else: - hook(**kwargs) + getattr(extension, event)(**kwargs) builtin_extensions: set[str] = { - # YORE: Bump 1: Remove line. - "hybrid", "dataclasses", } """The names of built-in Griffe extensions.""" @@ -454,10 +271,9 @@ def _load_extension_path(path: str) -> ModuleType: return module -# YORE: Bump 1: Replace `ExtensionType` with `Extension` within block. def _load_extension( - extension: str | dict[str, Any] | ExtensionType | type[ExtensionType], -) -> ExtensionType | list[ExtensionType]: + extension: str | dict[str, Any] | Extension | type[Extension], +) -> Extension | list[Extension]: """Load a configured extension. Parameters: @@ -474,17 +290,12 @@ def _load_extension( """ ext_object = None - # YORE: Bump 1: Remove line. - ext_classes = (VisitorExtension, InspectorExtension, Extension) - # If it's already an extension instance, return it. - # YORE: Bump 1: Replace `ext_classes` with `Extension` within line. - if isinstance(extension, ext_classes): + if isinstance(extension, Extension): return extension # If it's an extension class, instantiate it (without options) and return it. - # YORE: Bump 1: Replace `ext_classes` with `Extension` within line. - if isclass(extension) and issubclass(extension, ext_classes): + if isclass(extension) and issubclass(extension, Extension): return extension() # If it's a dictionary, we expect the only key to be an import path @@ -530,8 +341,7 @@ def _load_extension( raise ExtensionNotLoadedError(f"Error while importing extension '{import_path}': {error}") from error # If the loaded object is an extension class, instantiate it with options and return it. - # YORE: Bump 1: Replace `ext_classes` with `Extension` within line. - if isclass(ext_object) and issubclass(ext_object, ext_classes): + if isclass(ext_object) and issubclass(ext_object, Extension): return ext_object(**options) # Otherwise the loaded object is a module, so we get the extension class by name, @@ -548,17 +358,12 @@ def _load_extension( # instantiate each with the same options, and return them. extensions = [] for obj in vars(ext_object).values(): - # YORE: Bump 1: Replace `ext_classes` with `Extension` within line. - # YORE: Bump 1: Replace `not in` with `is not` within line. - if isclass(obj) and issubclass(obj, ext_classes) and obj not in ext_classes: + if isclass(obj) and issubclass(obj, Extension) and obj is not Extension: extensions.append(obj) return [ext(**options) for ext in extensions] -def load_extensions( - # YORE: Bump 1: Replace ` | Sequence[LoadableExtension],` with `` within line. - *exts: LoadableExtensionType | Sequence[LoadableExtensionType], -) -> Extensions: +def load_extensions(*exts: LoadableExtensionType) -> Extensions: """Load configured extensions. Parameters: @@ -569,22 +374,7 @@ def load_extensions( """ extensions = Extensions() - # YORE: Bump 1: Remove block. - all_exts: list[LoadableExtensionType] = [] - for ext in exts: - if isinstance(ext, (list, tuple)): - warnings.warn( - "Passing multiple extensions as a single list or tuple is deprecated. " - "Please pass them as separate arguments instead.", - DeprecationWarning, - stacklevel=2, - ) - all_exts.extend(ext) - else: - all_exts.append(ext) # type: ignore[arg-type] - - # YORE: Bump 1: Replace `all_exts` with `exts` within line. - for extension in all_exts: + for extension in exts: ext = _load_extension(extension) if isinstance(ext, list): extensions.add(*ext) diff --git a/src/_griffe/extensions/hybrid.py b/src/_griffe/extensions/hybrid.py index d1f344bc..e69de29b 100644 --- a/src/_griffe/extensions/hybrid.py +++ b/src/_griffe/extensions/hybrid.py @@ -1,94 +0,0 @@ -# Deprecated. This extension provides an hybrid behavior while loading data. - -# YORE: Bump 1: Remove file. - -from __future__ import annotations - -import re -from typing import TYPE_CHECKING, Any, Pattern, Sequence - -from _griffe.agents.nodes.runtime import ObjectNode -from _griffe.enumerations import When -from _griffe.exceptions import ExtensionError -from _griffe.extensions.base import InspectorExtension, VisitorExtension, _load_extension -from _griffe.importer import dynamic_import -from _griffe.logger import get_logger - -if TYPE_CHECKING: - import ast - - from _griffe.agents.visitor import Visitor - -_logger = get_logger("griffe.extensions.hybrid") - - -class HybridExtension(VisitorExtension): - """Inspect during a visit. - - This extension accepts the name of another extension (an inspector) - and runs it appropriately. It allows to inspect objects - after having visited them, so as to extract more data. - - Indeed, during the visit, an object might be seen as a simple - attribute (assignment), when in fact it's a function or a class - dynamically constructed. In this case, inspecting it will - provide the desired data. - """ - - when = When.after_all - """The moment when the extension should be executed.""" - - def __init__( - self, - extensions: Sequence[str | dict[str, Any] | InspectorExtension | type[InspectorExtension]], - object_paths: Sequence[str | Pattern] | None = None, - ) -> None: - """Initialize the extension. - - Parameters: - extensions: The names or configurations of other inspector extensions. - object_paths: Optional list of regular expressions to match against objects paths, - to select which objects to inspect. - - Raises: - ExtensionError: When the passed extension is not an inspector extension. - """ - self._extensions: list[InspectorExtension] = [_load_extension(ext) for ext in extensions] # type: ignore[misc] - for extension in self._extensions: - if not isinstance(extension, InspectorExtension): - raise ExtensionError( - f"Extension '{extension}' is not an inspector extension. " - "The 'hybrid' extension only accepts inspector extensions. " - "If you want to use a visitor extension, just add it normally " - "to your extensions configuration, without using 'hybrid'.", - ) - self.object_paths = [re.compile(op) if isinstance(op, str) else op for op in object_paths or []] - """The list of regular expressions to match against objects paths.""" - super().__init__() - - def attach(self, visitor: Visitor) -> None: - super().attach(visitor) - for extension in self._extensions: - extension.attach(visitor) # type: ignore[arg-type] # tolerate hybrid behavior - - def visit(self, node: ast.AST) -> None: - try: - just_visited = self.visitor.current.get_member(node.name) # type: ignore[attr-defined] - except (KeyError, AttributeError, TypeError): - return - if self.object_paths and not any(op.search(just_visited.path) for op in self.object_paths): - return - if just_visited.is_alias: - return - try: - value = dynamic_import(just_visited.path) - except AttributeError: - # can happen when an object is defined conditionally, - # for example based on the Python version - return - parent = None - for part in just_visited.path.split(".")[:-1]: - parent = ObjectNode(None, name=part, parent=parent) - object_node = ObjectNode(value, name=node.name, parent=parent) # type: ignore[attr-defined] - for extension in self._extensions: - extension.inspect(object_node) diff --git a/src/_griffe/finder.py b/src/_griffe/finder.py index ba01d855..66f86f59 100644 --- a/src/_griffe/finder.py +++ b/src/_griffe/finder.py @@ -28,18 +28,13 @@ from typing import TYPE_CHECKING, ClassVar, Iterator, Sequence, Tuple from _griffe.exceptions import UnhandledEditableModuleError - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger if TYPE_CHECKING: from typing import Pattern from _griffe.models import Module -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.finder") _editable_editables_patterns = [re.compile(pat) for pat in (r"^__editables_\w+\.py$", r"^_editable_impl_\w+\.py$")] _editable_setuptools_patterns = [re.compile(pat) for pat in (r"^__editable__\w+\.py$",)] @@ -323,7 +318,7 @@ def iter_submodules( for subpath in self._filter_py_modules(path): rel_subpath = subpath.relative_to(path) if rel_subpath.parent in skip: - _logger.debug(f"Skip {subpath}, another module took precedence") + logger.debug(f"Skip {subpath}, another module took precedence") continue py_file = rel_subpath.suffix == ".py" stem = rel_subpath.stem diff --git a/src/_griffe/importer.py b/src/_griffe/importer.py index 5bebfdea..48fb5848 100644 --- a/src/_griffe/importer.py +++ b/src/_griffe/importer.py @@ -117,6 +117,6 @@ def dynamic_import(import_path: str, import_paths: Sequence[str | Path] | None = value = getattr(value, part) except BaseException as error: # noqa: BLE001 errors.append(_error_details(error, module_path + ":" + ".".join(object_parts))) - raise ImportError("; ".join(errors)) # noqa: B904,TRY200 + raise ImportError("; ".join(errors)) # noqa: B904 return value diff --git a/src/_griffe/loader.py b/src/_griffe/loader.py index 80f803c4..d7ac480a 100644 --- a/src/_griffe/loader.py +++ b/src/_griffe/loader.py @@ -3,7 +3,6 @@ from __future__ import annotations import sys -import warnings from contextlib import suppress from datetime import datetime, timezone from pathlib import Path @@ -25,10 +24,7 @@ from _griffe.finder import ModuleFinder, NamespacePackage, Package from _griffe.git import tmp_worktree from _griffe.importer import dynamic_import - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger from _griffe.merger import merge_stubs from _griffe.models import Alias, Module, Object from _griffe.stats import Stats @@ -36,8 +32,6 @@ if TYPE_CHECKING: from _griffe.enumerations import Parser -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.loader") _builtin_modules: set[str] = set(sys.builtin_module_names) @@ -98,31 +92,6 @@ def __init__( "time_spent_inspecting": 0, } - # YORE: Bump 1: Remove block. - def load_module( - self, - module: str | Path, - *, - submodules: bool = True, - try_relative_path: bool = True, - find_stubs_package: bool = False, - ) -> Object: - """Renamed `load`. Load an object as a Griffe object, given its dotted path. - - This method was renamed [`load`][griffe.GriffeLoader.load]. - """ - warnings.warn( - "The `load_module` method was renamed `load`, and is deprecated.", - DeprecationWarning, - stacklevel=2, - ) - return self.load( # type: ignore[return-value] - module, - submodules=submodules, - try_relative_path=try_relative_path, - find_stubs_package=find_stubs_package, - ) - def load( self, objspec: str | Path | None = None, @@ -131,8 +100,6 @@ def load( submodules: bool = True, try_relative_path: bool = True, find_stubs_package: bool = False, - # YORE: Bump 1: Remove line. - module: str | Path | None = None, ) -> Object | Alias: """Load an object as a Griffe object, given its Python or file path. @@ -153,7 +120,6 @@ def load( find_stubs_package: Whether to search for stubs-only package. If both the package and its stubs are found, they'll be merged together. If only the stubs are found, they'll be used as the package itself. - module: Deprecated. Use `objspec` positional-only parameter instead. Raises: LoadingError: When loading a module failed for various reasons. @@ -162,24 +128,13 @@ def load( Returns: A Griffe object. """ - # YORE: Bump 1: Remove block. - if objspec is None and module is None: - raise TypeError("load() missing 1 required positional argument: 'objspec'") - if objspec is None: - objspec = module - warnings.warn( - "Parameter 'module' was renamed 'objspec' and made positional-only.", - DeprecationWarning, - stacklevel=2, - ) - obj_path: str package = None top_module = None # We always start by searching paths on the disk, # even if inspection is forced. - _logger.debug(f"Searching path(s) for {objspec}") + logger.debug(f"Searching path(s) for {objspec}") try: obj_path, package = self.finder.find_spec( objspec, # type: ignore[arg-type] @@ -189,14 +144,14 @@ def load( except ModuleNotFoundError: # If we couldn't find paths on disk and inspection is disabled, # re-raise ModuleNotFoundError. - _logger.debug(f"Could not find path for {objspec} on disk") + logger.debug(f"Could not find path for {objspec} on disk") if not (self.allow_inspection or self.force_inspection): raise # Otherwise we try to dynamically import the top-level module. obj_path = str(objspec) top_module_name = obj_path.split(".", 1)[0] - _logger.debug(f"Trying to dynamically import {top_module_name}") + logger.debug(f"Trying to dynamically import {top_module_name}") top_module_object = dynamic_import(top_module_name, self.finder.search_paths) try: @@ -206,7 +161,7 @@ def load( except (AttributeError, ValueError): # If the top-level module has no `__path__`, we inspect it as-is, # and do not try to recurse into submodules (there shouldn't be any in builtin/compiled modules). - _logger.debug(f"Module {top_module_name} has no paths set (built-in module?). Inspecting it as-is.") + logger.debug(f"Module {top_module_name} has no paths set (built-in module?). Inspecting it as-is.") top_module = self._inspect_module(top_module_name) self.modules_collection.set_member(top_module.path, top_module) obj = self.modules_collection.get_member(obj_path) @@ -214,7 +169,7 @@ def load( return obj # We found paths, and use them to build our intermediate Package or NamespacePackage struct. - _logger.debug(f"Module {top_module_name} has paths set: {top_module_path}") + logger.debug(f"Module {top_module_name} has paths set: {top_module_path}") top_module_path = [Path(path) for path in top_module_path] if len(top_module_path) > 1: package = NamespacePackage(top_module_name, top_module_path) @@ -222,11 +177,11 @@ def load( package = Package(top_module_name, top_module_path[0]) # We have an intermediate package, and an object path: we're ready to load. - _logger.debug(f"Found {objspec}: loading") + logger.debug(f"Found {objspec}: loading") try: top_module = self._load_package(package, submodules=submodules) except LoadingError as error: - _logger.exception(str(error)) # noqa: TRY401 + logger.exception(str(error)) raise # Package is loaded, we now retrieve the initially requested object and return it. @@ -282,7 +237,7 @@ def resolve_aliases( ) resolved |= next_resolved unresolved |= next_unresolved - _logger.debug( + logger.debug( f"Iteration {iteration} finished, {len(resolved)} aliases resolved, still {len(unresolved)} to go", ) return unresolved, iteration @@ -308,21 +263,21 @@ def expand_exports(self, module: Module, seen: set | None = None) -> None: try: next_module = self.modules_collection.get_member(module_path) except KeyError: - _logger.debug(f"Cannot expand '{export.canonical_path}', try pre-loading corresponding package") + logger.debug(f"Cannot expand '{export.canonical_path}', try pre-loading corresponding package") continue if next_module.path not in seen: self.expand_exports(next_module, seen) try: expanded |= next_module.exports except TypeError: - _logger.warning(f"Unsupported item in {module.path}.__all__: {export} (use strings only)") + logger.warning(f"Unsupported item in {module.path}.__all__: {export} (use strings only)") # It's a string, simply add it to the current exports. else: with suppress(NameResolutionError): if not module.resolve(export).startswith(module.path): # NOTE: This won't work for built-in attributes during inspection, # since their canonical module cannot be determined. - _logger.debug( + logger.debug( f"Name `{export}` exported by module `{module.path}` doesn't come from this module or from a submodule.", ) expanded.add(export) @@ -367,14 +322,14 @@ def expand_wildcards( try: self.load(package, try_relative_path=False) except (ImportError, LoadingError) as error: - _logger.debug(f"Could not expand wildcard import {member.name} in {obj.path}: {error}") + logger.debug(f"Could not expand wildcard import {member.name} in {obj.path}: {error}") continue # Try getting the module from which every public object is imported. try: target = self.modules_collection.get_member(member.target_path) # type: ignore[union-attr] except KeyError: - _logger.debug( + logger.debug( f"Could not expand wildcard import {member.name} in {obj.path}: " f"{cast(Alias, member).target_path} not found in modules collection", ) @@ -385,7 +340,7 @@ def expand_wildcards( try: self.expand_wildcards(target, external=external, seen=seen) except (AliasResolutionError, CyclicAliasError) as error: - _logger.debug(f"Could not expand wildcard import {member.name} in {obj.path}: {error}") + logger.debug(f"Could not expand wildcard import {member.name} in {obj.path}: {error}") continue # Collect every imported object. @@ -497,17 +452,17 @@ def resolve_module_aliases( and package not in self.modules_collection ) if load_module: - _logger.debug(f"Failed to resolve alias {member.path} -> {target}") + logger.debug(f"Failed to resolve alias {member.path} -> {target}") try: self.load(package, try_relative_path=False) except (ImportError, LoadingError) as error: - _logger.debug(f"Could not follow alias {member.path}: {error}") + logger.debug(f"Could not follow alias {member.path}: {error}") load_failures.add(package) # TODO: Immediately try again? except CyclicAliasError as error: - _logger.debug(str(error)) + logger.debug(str(error)) else: - _logger.debug(f"Alias {member.path} was resolved to {member.final_target.path}") # type: ignore[union-attr] + logger.debug(f"Alias {member.path} was resolved to {member.final_target.path}") # type: ignore[union-attr] resolved.add(member.path) # Recurse into unseen modules and classes. @@ -578,7 +533,7 @@ def _load_module_path( submodules: bool = True, parent: Module | None = None, ) -> Module: - _logger.debug(f"Loading path {module_path}") + logger.debug(f"Loading path {module_path}") if isinstance(module_path, list): module = self._create_module(module_name, module_path) elif self.force_inspection: @@ -600,7 +555,7 @@ def _load_submodules(self, module: Module) -> None: def _load_submodule(self, module: Module, subparts: tuple[str, ...], subpath: Path) -> None: for subpart in subparts: if "." in subpart: - _logger.debug(f"Skip {subpath}, dots in filenames are not supported") + logger.debug(f"Skip {subpath}, dots in filenames are not supported") return try: parent_module = self._get_or_create_parent_module(module, subparts, subpath) @@ -624,7 +579,7 @@ def _load_submodule(self, module: Module, subparts: tuple[str, ...], subpath: Pa # It works when the namespace package appears in only one search path (`sys.path`), # but will fail if it appears in multiple search paths: Python will only find the first occurrence. # It's better to not falsely support this, and to warn users. - _logger.debug(f"{error}. Missing __init__ module?") + logger.debug(f"{error}. Missing __init__ module?") return submodule_name = subparts[-1] try: @@ -635,12 +590,12 @@ def _load_submodule(self, module: Module, subparts: tuple[str, ...], subpath: Pa parent=parent_module, ) except LoadingError as error: - _logger.debug(str(error)) + logger.debug(str(error)) else: if submodule_name in parent_module.members: member = parent_module.members[submodule_name] if member.is_alias or not member.is_module: - _logger.debug( + logger.debug( f"Submodule '{submodule.path}' is shadowing the member at the same path. " "We recommend renaming the member or the submodule (for example prefixing it with `_`), " "see https://mkdocstrings.github.io/griffe/best_practices/#avoid-member-submodule-name-shadowing.", @@ -755,8 +710,6 @@ def load( force_inspection: bool = False, store_source: bool = True, find_stubs_package: bool = False, - # YORE: Bump 1: Remove line. - module: str | Path | None = None, resolve_aliases: bool = False, resolve_external: bool | None = None, resolve_implicit: bool = False, @@ -815,7 +768,6 @@ def load( find_stubs_package: Whether to search for stubs-only package. If both the package and its stubs are found, they'll be merged together. If only the stubs are found, they'll be used as the package itself. - module: Deprecated. Use `objspec` positional-only parameter instead. resolve_aliases: Whether to resolve aliases. resolve_external: Whether to try to load unspecified modules to resolve aliases. Default value (`None`) means to load external modules only if they are the private sibling @@ -841,8 +793,6 @@ def load( submodules=submodules, try_relative_path=try_relative_path, find_stubs_package=find_stubs_package, - # YORE: Bump 1: Remove line. - module=module, ) if resolve_aliases: loader.resolve_aliases(implicit=resolve_implicit, external=resolve_external) @@ -865,8 +815,6 @@ def load_git( allow_inspection: bool = True, force_inspection: bool = False, find_stubs_package: bool = False, - # YORE: Bump 1: Remove line. - module: str | Path | None = None, resolve_aliases: bool = False, resolve_external: bool | None = None, resolve_implicit: bool = False, @@ -903,7 +851,6 @@ def load_git( find_stubs_package: Whether to search for stubs-only package. If both the package and its stubs are found, they'll be merged together. If only the stubs are found, they'll be used as the package itself. - module: Deprecated. Use `objspec` positional-only parameter instead. resolve_aliases: Whether to resolve aliases. resolve_external: Whether to try to load unspecified modules to resolve aliases. Default value (`None`) means to load external modules only if they are the private sibling @@ -918,10 +865,6 @@ def load_git( if isinstance(objspec, Path): objspec = worktree / objspec - # YORE: Bump 1: Remove block. - if isinstance(module, Path): - module = worktree / module - return load( objspec, submodules=submodules, @@ -935,8 +878,6 @@ def load_git( allow_inspection=allow_inspection, force_inspection=force_inspection, find_stubs_package=find_stubs_package, - # YORE: Bump 1: Remove line. - module=module, resolve_aliases=resolve_aliases, resolve_external=resolve_external, resolve_implicit=resolve_implicit, diff --git a/src/_griffe/logger.py b/src/_griffe/logger.py index 33b30ec6..f5a1f6d2 100644 --- a/src/_griffe/logger.py +++ b/src/_griffe/logger.py @@ -10,7 +10,6 @@ from __future__ import annotations import logging -import warnings from contextlib import contextmanager from typing import Any, Callable, ClassVar, Iterator @@ -53,40 +52,39 @@ def _patch_loggers(cls, get_logger_func: Callable) -> None: cls._default_logger = get_logger_func -# YORE: Bump 1: Regex-replace `^# ?` with `` within block. -# logger: Logger = Logger._get() -# """Our global logger, used throughout the library. -# -# Griffe's output and error messages are logging messages. -# -# Griffe provides the [`patch_loggers`][griffe.patch_loggers] -# function so dependent libraries can patch Griffe loggers as they see fit. -# -# For example, to fit in the MkDocs logging configuration -# and prefix each log message with the module name: -# -# ```python -# import logging -# from griffe import patch_loggers -# -# -# class LoggerAdapter(logging.LoggerAdapter): -# def __init__(self, prefix, logger): -# super().__init__(logger, {}) -# self.prefix = prefix -# -# def process(self, msg, kwargs): -# return f"{self.prefix}: {msg}", kwargs -# -# -# def get_logger(name): -# logger = logging.getLogger(f"mkdocs.plugins.{name}") -# return LoggerAdapter(name, logger) -# -# -# patch_loggers(get_logger) -# ``` -# """ +logger: Logger = Logger._get() +"""Our global logger, used throughout the library. + +Griffe's output and error messages are logging messages. + +Griffe provides the [`patch_loggers`][griffe.patch_loggers] +function so dependent libraries can patch Griffe loggers as they see fit. + +For example, to fit in the MkDocs logging configuration +and prefix each log message with the module name: + +```python +import logging +from griffe import patch_loggers + + +class LoggerAdapter(logging.LoggerAdapter): + def __init__(self, prefix, logger): + super().__init__(logger, {}) + self.prefix = prefix + + def process(self, msg, kwargs): + return f"{self.prefix}: {msg}", kwargs + + +def get_logger(name): + logger = logging.getLogger(f"mkdocs.plugins.{name}") + return LoggerAdapter(name, logger) + + +patch_loggers(get_logger) +``` +""" def get_logger(name: str = "griffe") -> Logger: @@ -101,21 +99,6 @@ def get_logger(name: str = "griffe") -> Logger: return Logger._get(name) -# YORE: Bump 1: Remove block. -def patch_logger(get_logger_func: Callable[[str], Any]) -> None: - """Deprecated. Use `patch_loggers` instead. - - Parameters: - get_logger_func: A function accepting a name as parameter and returning a logger. - """ - warnings.warn( - "The `patch_logger` function is deprecated. Use `patch_loggers` instead.", - DeprecationWarning, - stacklevel=1, - ) - Logger._patch_loggers(get_logger_func) - - def patch_loggers(get_logger_func: Callable[[str], Any]) -> None: """Patch Griffe logger and Griffe extensions' loggers. diff --git a/src/_griffe/merger.py b/src/_griffe/merger.py index 4a523783..7ec80788 100644 --- a/src/_griffe/merger.py +++ b/src/_griffe/merger.py @@ -6,19 +6,12 @@ from typing import TYPE_CHECKING from _griffe.exceptions import AliasResolutionError, CyclicAliasError - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger if TYPE_CHECKING: from _griffe.models import Attribute, Class, Function, Module, Object -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.merger") - - def _merge_module_stubs(module: Module, stubs: Module) -> None: _merge_stubs_docstring(module, stubs) _merge_stubs_overloads(module, stubs) @@ -72,7 +65,7 @@ def _merge_stubs_members(obj: Module | Class, stubs: Module | Class) -> None: # not the canonical one. Therefore, we must allow merging stubs into the target of an alias, # as long as the stub and target are of the same kind. if obj_member.kind is not stub_member.kind: - _logger.debug( + logger.debug( f"Cannot merge stubs for {obj_member.path}: kind {stub_member.kind.value} != {obj_member.kind.value}", ) elif obj_member.is_module: @@ -101,7 +94,7 @@ def merge_stubs(mod1: Module, mod2: Module) -> Module: Returns: The regular module. """ - _logger.debug(f"Trying to merge {mod1.filepath} and {mod2.filepath}") + logger.debug(f"Trying to merge {mod1.filepath} and {mod2.filepath}") if mod1.filepath.suffix == ".pyi": # type: ignore[union-attr] stubs = mod1 module = mod2 diff --git a/src/_griffe/mixins.py b/src/_griffe/mixins.py index 4e163f9a..37475d3a 100644 --- a/src/_griffe/mixins.py +++ b/src/_griffe/mixins.py @@ -10,17 +10,11 @@ from _griffe.enumerations import Kind from _griffe.exceptions import AliasResolutionError, CyclicAliasError - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger from _griffe.merger import merge_stubs if TYPE_CHECKING: from _griffe.models import Alias, Attribute, Class, Function, Module, Object -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.mixins") _ObjType = TypeVar("_ObjType") @@ -453,38 +447,32 @@ def is_public(self) -> bool: """ # Give priority to the `public` attribute if it is set. if self.public is not None: # type: ignore[attr-defined] - # YORE: Bump 1: Replace line with `return self.public`. - return _True if self.public else _False # type: ignore[return-value,attr-defined] + return self.public # type: ignore[attr-defined] # If the object is a module and its name does not start with an underscore, it is public. # Modules are not subject to the `__all__` convention, only the underscore prefix one. if not self.is_alias and self.is_module and not self.name.startswith("_"): # type: ignore[attr-defined] - # YORE: Bump 1: Replace line with `return True`. - return _True # type: ignore[return-value] + return True # If the object is defined at the module-level and is listed in `__all__`, it is public. # If the parent module defines `__all__` but does not list the object, it is private. if self.parent and self.parent.is_module and bool(self.parent.exports): # type: ignore[attr-defined] - # YORE: Bump 1: Replace line with `return self.name in self.parent.exports`. - return _True if self.name in self.parent.exports else _False # type: ignore[attr-defined,return-value] + return self.name in self.parent.exports # type: ignore[attr-defined] # Special objects are always considered public. # Even if we don't access them directly, they are used through different *public* means # like instantiating classes (`__init__`), using operators (`__eq__`), etc.. if self.is_private: - # YORE: Bump 1: Replace line with `return False`. - return _False # type: ignore[return-value] + return False # TODO: In a future version, we will support two conventions regarding imports: # - `from a import x as x` marks `x` as public. # - `from a import *` marks all wildcard imported objects as public. - if self.is_imported: - # YORE: Bump 1: Replace line with `return False`. - return _False # type: ignore[return-value] + if self.is_imported: # noqa: SIM103 + return False # If we reached this point, the object is public. - # YORE: Bump 1: Replace line with `return True`. - return _True # type: ignore[return-value] + return True @property def is_deprecated(self) -> bool: diff --git a/src/_griffe/models.py b/src/_griffe/models.py index b721f067..1eacc026 100644 --- a/src/_griffe/models.py +++ b/src/_griffe/models.py @@ -16,10 +16,7 @@ from _griffe.enumerations import Kind, ParameterKind, Parser from _griffe.exceptions import AliasResolutionError, BuiltinModuleError, CyclicAliasError, NameResolutionError from _griffe.expressions import ExprCall, ExprName - -# YORE: Bump 1: Replace `_logger` with `logger` within file. -# YORE: Bump 1: Replace `get_logger` with `logger` within line. -from _griffe.logger import get_logger +from _griffe.logger import logger from _griffe.mixins import ObjectAliasMixin if TYPE_CHECKING: @@ -29,9 +26,6 @@ from functools import cached_property -# YORE: Bump 1: Remove line. -_logger = get_logger("griffe.dataclasses") - class Decorator: """This class represents decorators.""" @@ -151,23 +145,17 @@ def as_dict( self, *, full: bool = False, - docstring_parser: Parser | None = None, **kwargs: Any, # noqa: ARG002 ) -> dict[str, Any]: """Return this docstring's data as a dictionary. Parameters: full: Whether to return full info, or just base info. - docstring_parser: Deprecated. The docstring parser to parse the docstring with. By default, no parsing is done. **kwargs: Additional serialization options. Returns: A dictionary. """ - # YORE: Bump 1: Remove block. - if docstring_parser is not None: - warnings.warn("Parameter `docstring_parser` is deprecated and has no effect.", stacklevel=1) - base: dict[str, Any] = { "value": self.value, "lineno": self.lineno, @@ -510,7 +498,7 @@ def inherited_members(self) -> dict[str, Alias]: try: mro = self.mro() except ValueError as error: - _logger.debug(error) + logger.debug(error) return {} inherited_members = {} for base in reversed(mro): @@ -564,8 +552,7 @@ def is_namespace_subpackage(self) -> bool: """Whether this object is a namespace subpackage.""" return False - # YORE: Bump 1: Replace ` | set[str]` with `` within line. - def has_labels(self, *labels: str | set[str]) -> bool: + def has_labels(self, *labels: str) -> bool: """Tell if this object has all the given labels. Parameters: @@ -574,21 +561,7 @@ def has_labels(self, *labels: str | set[str]) -> bool: Returns: True or False. """ - # YORE: Bump 1: Remove block. - all_labels = set() - for label in labels: - if isinstance(label, str): - all_labels.add(label) - else: - warnings.warn( - "Passing a set of labels to `has_labels` is deprecated. Pass multiple strings instead.", - DeprecationWarning, - stacklevel=2, - ) - all_labels.update(label) - - # YORE: Bump 1: Replace `all_labels` with `set(labels)` within line. - return all_labels.issubset(self.labels) + return set(labels).issubset(self.labels) def filter_members(self, *predicates: Callable[[Object | Alias], bool]) -> dict[str, Object | Alias]: """Filter and return members based on predicates. @@ -862,9 +835,7 @@ def as_dict(self, *, full: bool = False, **kwargs: Any) -> dict[str, Any]: base["docstring"] = self.docstring base["labels"] = self.labels - # YORE: Bump 1: Replace line with `base["members"] = {name: member.as_dict(full=full, **kwargs) for name, member in self.members.items()}`. - base["members"] = [member.as_dict(full=full, **kwargs) for member in self.members.values()] - # Also replace array and items by object and additionalProperties in docs/schema.json line 163. + base["members"] = {name: member.as_dict(full=full, **kwargs) for name, member in self.members.items()} return base @@ -1167,7 +1138,7 @@ def is_attribute(self) -> bool: """Whether this object is an attribute.""" return self.final_target.is_attribute - def has_labels(self, *labels: str | set[str]) -> bool: + def has_labels(self, *labels: str) -> bool: """Tell if this object has all the given labels. Parameters: @@ -1349,12 +1320,12 @@ def returns(self, returns: str | Expr | None) -> None: @property def setter(self) -> Function | None: """The setter linked to this function (property).""" - return cast(Function, self.final_target).setter + return cast(Attribute, self.final_target).setter @property def deleter(self) -> Function | None: """The deleter linked to this function (property).""" - return cast(Function, self.final_target).deleter + return cast(Attribute, self.final_target).deleter @property def value(self) -> str | Expr | None: @@ -1678,7 +1649,7 @@ def resolved_bases(self) -> list[Object]: if resolved_base.is_alias: resolved_base = resolved_base.final_target except (AliasResolutionError, CyclicAliasError, KeyError): - _logger.debug(f"Base class {base_path} is not loaded, or not static, it cannot be resolved") + logger.debug(f"Base class {base_path} is not loaded, or not static, it cannot be resolved") else: resolved_bases.append(resolved_base) return resolved_bases @@ -1744,11 +1715,6 @@ def __init__( """The function decorators.""" self.overloads: list[Function] | None = None """The overloaded signatures of this function.""" - # YORE: Bump 1: Remove block. - self.setter: Function | None = None - """Deprecated. See [Attribute.setter][griffe.Attribute.setter].""" - self.deleter: Function | None = None - """Deprecated. See [Attribute.deleter][griffe.Attribute.deleter].""" for parameter in self.parameters: parameter.function = self diff --git a/src/griffe/__init__.py b/src/griffe/__init__.py index 4412836a..b7d1f674 100644 --- a/src/griffe/__init__.py +++ b/src/griffe/__init__.py @@ -106,7 +106,7 @@ parsers, ) from _griffe.docstrings.sphinx import parse_sphinx -from _griffe.docstrings.utils import DocstringWarningCallable, docstring_warning, parse_docstring_annotation +from _griffe.docstrings.utils import docstring_warning, parse_docstring_annotation from _griffe.encoders import JSONEncoder, json_decoder from _griffe.enumerations import ( BreakageKind, @@ -117,8 +117,6 @@ ObjectKind, ParameterKind, Parser, - # YORE: Bump 1: Remove line. - When, ) from _griffe.exceptions import ( AliasResolutionError, @@ -180,28 +178,16 @@ from _griffe.extensions.base import ( Extension, Extensions, - # YORE: Bump 1: Remove line. - ExtensionType, - # YORE: Bump 1: Remove line. - InspectorExtension, LoadableExtensionType, - # YORE: Bump 1: Remove line. - VisitorExtension, builtin_extensions, load_extensions, ) from _griffe.extensions.dataclasses import DataclassesExtension - -# YORE: Bump 1: Remove line. -from _griffe.extensions.hybrid import HybridExtension from _griffe.finder import ModuleFinder, NamePartsAndPathType, NamePartsType, NamespacePackage, Package from _griffe.git import assert_git_repo, get_latest_tag, get_repo_root, tmp_worktree from _griffe.importer import dynamic_import, sys_path from _griffe.loader import GriffeLoader, load, load_git, load_pypi - -# YORE: Bump 1: Replace `get_logger` with `get_logger, logger` within line. -# YORE: Bump 1: Replace `patch_logger, ` with `` within line. -from _griffe.logger import Logger, get_logger, patch_logger, patch_loggers +from _griffe.logger import Logger, get_logger, logger, patch_loggers from _griffe.merger import merge_stubs from _griffe.mixins import ( DelMembersMixin, @@ -289,8 +275,6 @@ "DocstringSectionYields", "DocstringStyle", "DocstringWarn", - # YORE: Bump 1: Remove line. - "DocstringWarningCallable", "DocstringYield", "ExplanationStyle", "ExportedName", @@ -329,19 +313,13 @@ "Extension", "ExtensionError", "ExtensionNotLoadedError", - # YORE: Bump 1: Remove line. - "ExtensionType", "Extensions", "Function", "GetMembersMixin", "GitError", "GriffeError", "GriffeLoader", - # YORE: Bump 1: Remove line. - "HybridExtension", "Inspector", - # YORE: Bump 1: Remove line. - "InspectorExtension", "JSONEncoder", "Kind", "LastNodeError", @@ -384,10 +362,6 @@ "UnhandledEditableModuleError", "UnimportableModuleError", "Visitor", - # YORE: Bump 1: Remove line. - "VisitorExtension", - # YORE: Bump 1: Remove line. - "When", "assert_git_repo", "ast_children", "ast_first_child", @@ -429,8 +403,7 @@ "load_extensions", "load_git", "load_pypi", - # YORE: Bump 1: Replace `# ` with ``. - # "logger", + "logger", "main", "merge_stubs", "module_vtree", @@ -441,8 +414,6 @@ "parse_numpy", "parse_sphinx", "parsers", - # YORE: Bump 1: Remove line. - "patch_logger", "patch_loggers", "relative_to_absolute", "safe_get__all__", diff --git a/src/griffe/agents/__init__.py b/src/griffe/agents/__init__.py deleted file mode 100644 index e6f4aabd..00000000 --- a/src/griffe/agents/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.agents` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/agents/inspector.py b/src/griffe/agents/inspector.py deleted file mode 100644 index c8ae23fb..00000000 --- a/src/griffe/agents/inspector.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.agents.inspector` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/agents/nodes.py b/src/griffe/agents/nodes.py deleted file mode 100644 index b84c5007..00000000 --- a/src/griffe/agents/nodes.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.agents.nodes` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - if name == "Name": - warnings.warn( - "The `Name` class was renamed `ExportedName`.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.ExportedName - return getattr(griffe, name) diff --git a/src/griffe/agents/visitor.py b/src/griffe/agents/visitor.py deleted file mode 100644 index 39b66539..00000000 --- a/src/griffe/agents/visitor.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.agents.visitor` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/c3linear.py b/src/griffe/c3linear.py deleted file mode 100644 index ad9ac2b0..00000000 --- a/src/griffe/c3linear.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.c3linear` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/cli.py b/src/griffe/cli.py deleted file mode 100644 index 3687b757..00000000 --- a/src/griffe/cli.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.cli` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/collections.py b/src/griffe/collections.py deleted file mode 100644 index cfa1e39c..00000000 --- a/src/griffe/collections.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.collections` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/dataclasses.py b/src/griffe/dataclasses.py deleted file mode 100644 index 9d93ea75..00000000 --- a/src/griffe/dataclasses.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.dataclasses` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/diff.py b/src/griffe/diff.py deleted file mode 100644 index 91858e7b..00000000 --- a/src/griffe/diff.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.diff` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/docstrings/__init__.py b/src/griffe/docstrings/__init__.py deleted file mode 100644 index 68a07db1..00000000 --- a/src/griffe/docstrings/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.docstrings` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/docstrings/dataclasses.py b/src/griffe/docstrings/dataclasses.py deleted file mode 100644 index 3d35e3ea..00000000 --- a/src/griffe/docstrings/dataclasses.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.docstrings.dataclasses` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/docstrings/google.py b/src/griffe/docstrings/google.py deleted file mode 100644 index cdcb96f2..00000000 --- a/src/griffe/docstrings/google.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.docstrings.google` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - if name == "parse": - warnings.warn( - "The 'parse' function was renamed 'parse_google'.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.parse_google - return getattr(griffe, name) diff --git a/src/griffe/docstrings/numpy.py b/src/griffe/docstrings/numpy.py deleted file mode 100644 index 086ba608..00000000 --- a/src/griffe/docstrings/numpy.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.docstrings.numpy` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - if name == "parse": - warnings.warn( - "The 'parse' function was renamed 'parse_numpy'.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.parse_numpy - return getattr(griffe, name) diff --git a/src/griffe/docstrings/parsers.py b/src/griffe/docstrings/parsers.py deleted file mode 100644 index 4af4ffec..00000000 --- a/src/griffe/docstrings/parsers.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.docstrings.parsers` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/docstrings/sphinx.py b/src/griffe/docstrings/sphinx.py deleted file mode 100644 index d8db028f..00000000 --- a/src/griffe/docstrings/sphinx.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.docstrings.sphinx` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - if name == "parse": - warnings.warn( - "The 'parse' function was renamed 'parse_sphinx'.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.parse_sphinx - return getattr(griffe, name) diff --git a/src/griffe/docstrings/utils.py b/src/griffe/docstrings/utils.py deleted file mode 100644 index 0d550c0f..00000000 --- a/src/griffe/docstrings/utils.py +++ /dev/null @@ -1,38 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.docstrings.utils` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - if name == "WarningCallable": - warnings.warn( - "The 'WarningCallable' class was renamed 'DocstringWarningCallable'.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.DocstringWarningCallable - if name == "warning": - warnings.warn( - "The 'warning' function was renamed 'docstring_warning'.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.docstring_warning - if name == "parse_annotation": - warnings.warn( - "The 'parse_annotation' function was renamed 'parse_docstring_annotation'.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.parse_docstring_annotation - return getattr(griffe, name) diff --git a/src/griffe/encoders.py b/src/griffe/encoders.py deleted file mode 100644 index f4732fba..00000000 --- a/src/griffe/encoders.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.encoders` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/enumerations.py b/src/griffe/enumerations.py deleted file mode 100644 index 9d2ff622..00000000 --- a/src/griffe/enumerations.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.enumerations` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/exceptions.py b/src/griffe/exceptions.py deleted file mode 100644 index 6dc0f306..00000000 --- a/src/griffe/exceptions.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.exceptions` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/expressions.py b/src/griffe/expressions.py deleted file mode 100644 index edff837f..00000000 --- a/src/griffe/expressions.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.expressions` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/extensions/__init__.py b/src/griffe/extensions/__init__.py deleted file mode 100644 index 929fe915..00000000 --- a/src/griffe/extensions/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.extensions` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/extensions/base.py b/src/griffe/extensions/base.py deleted file mode 100644 index b4138b5f..00000000 --- a/src/griffe/extensions/base.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.extensions.base` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/extensions/dataclasses.py b/src/griffe/extensions/dataclasses.py deleted file mode 100644 index 549be610..00000000 --- a/src/griffe/extensions/dataclasses.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.extensions.dataclasses` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/extensions/hybrid.py b/src/griffe/extensions/hybrid.py deleted file mode 100644 index 31ea73a0..00000000 --- a/src/griffe/extensions/hybrid.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.extensions.hybrid` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/finder.py b/src/griffe/finder.py deleted file mode 100644 index 0ec8a748..00000000 --- a/src/griffe/finder.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.finder` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/git.py b/src/griffe/git.py deleted file mode 100644 index f71162e5..00000000 --- a/src/griffe/git.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.git` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/importer.py b/src/griffe/importer.py deleted file mode 100644 index c872edf2..00000000 --- a/src/griffe/importer.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.importer` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/loader.py b/src/griffe/loader.py deleted file mode 100644 index dc7aae59..00000000 --- a/src/griffe/loader.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.loader` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/logger.py b/src/griffe/logger.py deleted file mode 100644 index 24fd5c5c..00000000 --- a/src/griffe/logger.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.logger` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/merger.py b/src/griffe/merger.py deleted file mode 100644 index 102b955b..00000000 --- a/src/griffe/merger.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.merger` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/mixins.py b/src/griffe/mixins.py deleted file mode 100644 index c95dec1b..00000000 --- a/src/griffe/mixins.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.mixins` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/src/griffe/stats.py b/src/griffe/stats.py deleted file mode 100644 index ca560fb6..00000000 --- a/src/griffe/stats.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.stats` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - if name == "stats": - warnings.warn( - "The 'stats' function was made into a class and renamed 'Stats'.", - DeprecationWarning, - stacklevel=2, - ) - return griffe.Stats - return getattr(griffe, name) diff --git a/src/griffe/tests.py b/src/griffe/tests.py deleted file mode 100644 index 225db1ad..00000000 --- a/src/griffe/tests.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Deprecated. Import from `griffe` directly.""" - -from __future__ import annotations - -import warnings -from typing import Any - -import griffe - - -def __getattr__(name: str) -> Any: - warnings.warn( - "Importing from `griffe.tests` is deprecated. Import from `griffe` directly instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(griffe, name) diff --git a/tests/test_cli.py b/tests/test_cli.py index 2e65bf4c..f9686400 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -5,6 +5,7 @@ import sys import pytest + from _griffe import cli, debug diff --git a/tests/test_docstrings/conftest.py b/tests/test_docstrings/conftest.py index 8a033bd0..86043893 100644 --- a/tests/test_docstrings/conftest.py +++ b/tests/test_docstrings/conftest.py @@ -5,12 +5,12 @@ from typing import Iterator import pytest -from _griffe.docstrings import google, numpy, sphinx +from _griffe.docstrings import google, numpy, sphinx from tests.test_docstrings.helpers import ParserType, parser -@pytest.fixture() +@pytest.fixture def parse_google() -> Iterator[ParserType]: """Yield a function to parse Google docstrings. @@ -20,7 +20,7 @@ def parse_google() -> Iterator[ParserType]: yield from parser(google) -@pytest.fixture() +@pytest.fixture def parse_numpy() -> Iterator[ParserType]: """Yield a function to parse Numpy docstrings. @@ -30,7 +30,7 @@ def parse_numpy() -> Iterator[ParserType]: yield from parser(numpy) -@pytest.fixture() +@pytest.fixture def parse_sphinx() -> Iterator[ParserType]: """Yield a function to parse Sphinx docstrings. diff --git a/tests/test_docstrings/helpers.py b/tests/test_docstrings/helpers.py index 48f89f88..0249e53a 100644 --- a/tests/test_docstrings/helpers.py +++ b/tests/test_docstrings/helpers.py @@ -40,7 +40,7 @@ def parser(parser_module: ModuleType) -> Iterator[ParserType]: Yields: The wrapped function. """ - original_warn = parser_module._warn + original_warn = parser_module.docstring_warning def parse(docstring: str, parent: ParentType | None = None, **parser_opts: Any) -> ParseResultType: """Parse a doctring. @@ -59,7 +59,9 @@ def parse(docstring: str, parent: ParentType | None = None, **parser_opts: Any) docstring_object.parent = parent parent.docstring = docstring_object warnings = [] - parser_module._warn = lambda _docstring, _offset, message, log_level=LogLevel.warning: warnings.append(message) # type: ignore[attr-defined] + parser_module.docstring_warning = ( # type: ignore[attr-defined] + lambda _docstring, _offset, message, log_level=LogLevel.warning: warnings.append(message) + ) func_name = f"parse_{parser_module.__name__.split('.')[-1]}" func = getattr(parser_module, func_name) sections = func(docstring_object, **parser_opts) @@ -67,4 +69,4 @@ def parse(docstring: str, parent: ParentType | None = None, **parser_opts: Any) yield parse - parser_module._warn = original_warn # type: ignore[attr-defined] + parser_module.docstring_warning = original_warn # type: ignore[attr-defined] diff --git a/tests/test_finder.py b/tests/test_finder.py index cb271228..21d94d27 100644 --- a/tests/test_finder.py +++ b/tests/test_finder.py @@ -7,8 +7,8 @@ from textwrap import dedent import pytest -from _griffe.finder import _handle_editable_module, _handle_pth_file +from _griffe.finder import _handle_editable_module, _handle_pth_file from griffe import Module, ModuleFinder, NamespacePackage, Package, temporary_pypackage diff --git a/tests/test_git.py b/tests/test_git.py index d471fca8..a1321a1e 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -35,7 +35,7 @@ def _copy_contents(src: Path, dst: Path) -> None: shutil.copy(src_path, dst_path) -@pytest.fixture() +@pytest.fixture def git_repo(tmp_path: Path) -> Path: """Fixture that creates a git repo with multiple tagged versions. diff --git a/tests/test_internals.py b/tests/test_internals.py index c671a58d..9f84a716 100644 --- a/tests/test_internals.py +++ b/tests/test_internals.py @@ -169,12 +169,7 @@ def test_inventory_matches_api( for item in inventory.values(): if item.domain == "py" and "(" not in item.name: obj = loader.modules_collection[item.name] - if ( - obj.path not in public_api_paths - and not any(path in public_api_paths for path in obj.aliases) - # YORE: Bump 1: Remove line. - and not (obj.is_module and obj.package.name == "griffe") - ): + if obj.path not in public_api_paths and not any(path in public_api_paths for path in obj.aliases): not_in_api.append(item.name) msg = "Inventory objects not in public API (try running `make run mkdocs build`):\n{paths}" assert not not_in_api, msg.format(paths="\n".join(sorted(not_in_api)))