From 3091660ae1b6253e481cedbdcc31b73c0ab334df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 12 Feb 2024 01:04:12 +0100 Subject: [PATCH] refactor: Use canonical imports --- src/griffe/__init__.py | 7 +++++-- src/griffe/agents/inspector.py | 20 ++++++------------- src/griffe/agents/nodes/__init__.py | 3 ++- src/griffe/agents/visitor.py | 31 ++++++++++++----------------- src/griffe/cli.py | 6 +++--- src/griffe/dataclasses.py | 4 ++-- src/griffe/diff.py | 4 ++-- src/griffe/docstrings/__init__.py | 3 ++- src/griffe/docstrings/google.py | 2 +- src/griffe/docstrings/numpy.py | 2 +- src/griffe/docstrings/utils.py | 2 +- src/griffe/encoders.py | 6 ++---- src/griffe/extensions/__init__.py | 2 +- src/griffe/extensions/hybrid.py | 3 ++- src/griffe/git.py | 4 ++-- src/griffe/loader.py | 7 ++++--- src/griffe/tests.py | 4 ++-- 17 files changed, 51 insertions(+), 59 deletions(-) diff --git a/src/griffe/__init__.py b/src/griffe/__init__.py index 17c94136..fe743c68 100644 --- a/src/griffe/__init__.py +++ b/src/griffe/__init__.py @@ -10,8 +10,11 @@ from griffe.agents.nodes import ObjectNode from griffe.dataclasses import Attribute, Class, Docstring, Function, Module, Object from griffe.diff import find_breaking_changes -from griffe.docstrings.parsers import Parser, parse_google, parse_numpy, parse_sphinx -from griffe.extensions import Extension, load_extensions +from griffe.docstrings.google import parse as parse_google +from griffe.docstrings.numpy import parse as parse_numpy +from griffe.docstrings.sphinx import parse as parse_sphinx +from griffe.enumerations import Parser +from griffe.extensions.base import Extension, load_extensions from griffe.git import load_git from griffe.importer import dynamic_import from griffe.loader import load diff --git a/src/griffe/agents/inspector.py b/src/griffe/agents/inspector.py index 01948aa0..27a5c97b 100644 --- a/src/griffe/agents/inspector.py +++ b/src/griffe/agents/inspector.py @@ -28,26 +28,18 @@ from inspect import signature as getsignature from typing import TYPE_CHECKING, Any, Sequence -from griffe.agents.nodes import ObjectKind, ObjectNode, safe_get_annotation +from griffe.agents.nodes import ObjectNode from griffe.collections import LinesCollection, ModulesCollection -from griffe.dataclasses import ( - Alias, - Attribute, - Class, - Docstring, - Function, - Module, - Parameter, - ParameterKind, - Parameters, -) -from griffe.extensions import Extensions +from griffe.dataclasses import Alias, Attribute, Class, Docstring, Function, Module, Parameter, Parameters +from griffe.enumerations import ObjectKind, ParameterKind +from griffe.expressions import safe_get_annotation +from griffe.extensions.base import Extensions from griffe.importer import dynamic_import if TYPE_CHECKING: from pathlib import Path - from griffe.docstrings.parsers import Parser + from griffe.enumerations import Parser from griffe.expressions import Expr diff --git a/src/griffe/agents/nodes/__init__.py b/src/griffe/agents/nodes/__init__.py index 34bdd579..703ac18b 100644 --- a/src/griffe/agents/nodes/__init__.py +++ b/src/griffe/agents/nodes/__init__.py @@ -18,8 +18,9 @@ from griffe.agents.nodes._imports import relative_to_absolute from griffe.agents.nodes._names import get_instance_names, get_name, get_names from griffe.agents.nodes._parameters import get_call_keyword_arguments -from griffe.agents.nodes._runtime import ObjectKind, ObjectNode +from griffe.agents.nodes._runtime import ObjectNode from griffe.agents.nodes._values import get_value, safe_get_value +from griffe.enumerations import ObjectKind from griffe.expressions import ( get_annotation, get_base_class, diff --git a/src/griffe/agents/visitor.py b/src/griffe/agents/visitor.py index 7884e841..ee561c70 100644 --- a/src/griffe/agents/visitor.py +++ b/src/griffe/agents/visitor.py @@ -22,32 +22,27 @@ get_names, relative_to_absolute, safe_get__all__, +) +from griffe.collections import LinesCollection, ModulesCollection +from griffe.dataclasses import Alias, Attribute, Class, Decorator, Docstring, Function, Module, Parameter, Parameters +from griffe.enumerations import Kind, ParameterKind +from griffe.exceptions import AliasResolutionError, CyclicAliasError, LastNodeError +from griffe.expressions import ( + Expr, + ExprAttribute, + ExprCall, + ExprName, safe_get_annotation, safe_get_base_class, safe_get_condition, + safe_get_expression, ) -from griffe.collections import LinesCollection, ModulesCollection -from griffe.dataclasses import ( - Alias, - Attribute, - Class, - Decorator, - Docstring, - Function, - Kind, - Module, - Parameter, - ParameterKind, - Parameters, -) -from griffe.exceptions import AliasResolutionError, CyclicAliasError, LastNodeError -from griffe.expressions import Expr, safe_get_expression -from griffe.extensions import Extensions +from griffe.extensions.base import Extensions if TYPE_CHECKING: from pathlib import Path - from griffe.docstrings.parsers import Parser + from griffe.enumerations import Parser builtin_decorators = { diff --git a/src/griffe/cli.py b/src/griffe/cli.py index 50ab3f3a..607c2aa3 100644 --- a/src/griffe/cli.py +++ b/src/griffe/cli.py @@ -25,9 +25,9 @@ import colorama from griffe import debug -from griffe.diff import ExplanationStyle, find_breaking_changes -from griffe.docstrings.parsers import Parser +from griffe.diff import find_breaking_changes from griffe.encoders import JSONEncoder +from griffe.enumerations import ExplanationStyle, Parser from griffe.exceptions import ExtensionError, GitError from griffe.extensions.base import load_extensions from griffe.git import _get_latest_tag, _get_repo_root, load_git @@ -36,7 +36,7 @@ from griffe.stats import _format_stats if TYPE_CHECKING: - from griffe.extensions import Extensions, ExtensionType + from griffe.extensions.base import Extensions, ExtensionType DEFAULT_LOG_LEVEL = os.getenv("GRIFFE_LOG_LEVEL", "INFO").upper() diff --git a/src/griffe/dataclasses.py b/src/griffe/dataclasses.py index f50456cc..6505808c 100644 --- a/src/griffe/dataclasses.py +++ b/src/griffe/dataclasses.py @@ -15,8 +15,8 @@ from typing import TYPE_CHECKING, Any, Callable, Literal, Sequence, Union, cast from griffe.c3linear import c3linear_merge -from griffe.docstrings.parsers import Parser, parse -from griffe.enumerations import Kind, ParameterKind +from griffe.docstrings.parsers import parse +from griffe.enumerations import Kind, ParameterKind, Parser from griffe.exceptions import AliasResolutionError, BuiltinModuleError, CyclicAliasError, NameResolutionError from griffe.expressions import ExprCall, ExprName from griffe.logger import get_logger diff --git a/src/griffe/diff.py b/src/griffe/diff.py index 449efaf9..db86ffb8 100644 --- a/src/griffe/diff.py +++ b/src/griffe/diff.py @@ -8,8 +8,8 @@ from colorama import Fore, Style -from griffe.dataclasses import Alias, Attribute, Class, Function, Object, ParameterKind -from griffe.enumerations import BreakageKind, ExplanationStyle +from griffe.dataclasses import Alias, Attribute, Class, Function, Object +from griffe.enumerations import BreakageKind, ExplanationStyle, ParameterKind from griffe.exceptions import AliasResolutionError from griffe.git import WORKTREE_PREFIX from griffe.logger import get_logger diff --git a/src/griffe/docstrings/__init__.py b/src/griffe/docstrings/__init__.py index 2e3f5a56..0a751f64 100644 --- a/src/griffe/docstrings/__init__.py +++ b/src/griffe/docstrings/__init__.py @@ -1,5 +1,6 @@ """This module exposes objects related to docstrings.""" -from griffe.docstrings.parsers import Parser, parse, parsers +from griffe.docstrings.parsers import parse, parsers +from griffe.enumerations import Parser __all__ = ["Parser", "parse", "parsers"] diff --git a/src/griffe/docstrings/google.py b/src/griffe/docstrings/google.py index e7a16ad7..a36852d6 100644 --- a/src/griffe/docstrings/google.py +++ b/src/griffe/docstrings/google.py @@ -22,7 +22,6 @@ DocstringSectionDeprecated, DocstringSectionExamples, DocstringSectionFunctions, - DocstringSectionKind, DocstringSectionModules, DocstringSectionOtherParameters, DocstringSectionParameters, @@ -36,6 +35,7 @@ DocstringYield, ) from griffe.docstrings.utils import parse_annotation, warning +from griffe.enumerations import DocstringSectionKind from griffe.expressions import ExprName from griffe.logger import LogLevel diff --git a/src/griffe/docstrings/numpy.py b/src/griffe/docstrings/numpy.py index da865a1d..4c2c902e 100644 --- a/src/griffe/docstrings/numpy.py +++ b/src/griffe/docstrings/numpy.py @@ -40,7 +40,6 @@ DocstringSectionDeprecated, DocstringSectionExamples, DocstringSectionFunctions, - DocstringSectionKind, DocstringSectionModules, DocstringSectionOtherParameters, DocstringSectionParameters, @@ -54,6 +53,7 @@ DocstringYield, ) from griffe.docstrings.utils import parse_annotation, warning +from griffe.enumerations import DocstringSectionKind from griffe.expressions import ExprName from griffe.logger import LogLevel diff --git a/src/griffe/docstrings/utils.py b/src/griffe/docstrings/utils.py index 59a88e44..b61cb403 100644 --- a/src/griffe/docstrings/utils.py +++ b/src/griffe/docstrings/utils.py @@ -6,8 +6,8 @@ from contextlib import suppress from typing import TYPE_CHECKING, Protocol -from griffe.agents.nodes import safe_get_annotation from griffe.exceptions import BuiltinModuleError +from griffe.expressions import safe_get_annotation from griffe.logger import LogLevel, get_logger if TYPE_CHECKING: diff --git a/src/griffe/encoders.py b/src/griffe/encoders.py index b8669d60..511150d0 100644 --- a/src/griffe/encoders.py +++ b/src/griffe/encoders.py @@ -20,19 +20,17 @@ Decorator, Docstring, Function, - Kind, Module, Object, Parameter, - ParameterKind, Parameters, ) -from griffe.docstrings.dataclasses import DocstringSectionKind +from griffe.enumerations import DocstringSectionKind, Kind, ParameterKind if TYPE_CHECKING: from enum import Enum - from griffe.docstrings.parsers import Parser + from griffe.enumerations import Parser def _enum_value(obj: Enum) -> str | int: diff --git a/src/griffe/extensions/__init__.py b/src/griffe/extensions/__init__.py index 0d05b2e1..43001e42 100644 --- a/src/griffe/extensions/__init__.py +++ b/src/griffe/extensions/__init__.py @@ -1,12 +1,12 @@ """This module is the public interface to import elements from the base.""" +from griffe.enumerations import When from griffe.extensions.base import ( Extension, Extensions, ExtensionType, InspectorExtension, VisitorExtension, - When, load_extensions, ) diff --git a/src/griffe/extensions/hybrid.py b/src/griffe/extensions/hybrid.py index 642d6e13..a03dcf28 100644 --- a/src/griffe/extensions/hybrid.py +++ b/src/griffe/extensions/hybrid.py @@ -6,8 +6,9 @@ from typing import TYPE_CHECKING, Any, Pattern, Sequence from griffe.agents.nodes import ObjectNode +from griffe.enumerations import When from griffe.exceptions import ExtensionError -from griffe.extensions.base import InspectorExtension, VisitorExtension, When, _load_extension +from griffe.extensions.base import InspectorExtension, VisitorExtension, _load_extension from griffe.importer import dynamic_import from griffe.logger import get_logger diff --git a/src/griffe/git.py b/src/griffe/git.py index 29f5a76e..ca5a683d 100644 --- a/src/griffe/git.py +++ b/src/griffe/git.py @@ -24,8 +24,8 @@ if TYPE_CHECKING: from griffe.collections import LinesCollection, ModulesCollection from griffe.dataclasses import Object - from griffe.docstrings.parsers import Parser - from griffe.extensions import Extensions + from griffe.enumerations import Parser + from griffe.extensions.base import Extensions WORKTREE_PREFIX = "griffe-worktree-" diff --git a/src/griffe/loader.py b/src/griffe/loader.py index 17f7c64d..dbf41c79 100644 --- a/src/griffe/loader.py +++ b/src/griffe/loader.py @@ -21,10 +21,11 @@ from griffe.agents.inspector import inspect from griffe.agents.visitor import visit from griffe.collections import LinesCollection, ModulesCollection -from griffe.dataclasses import Alias, Kind, Module, Object +from griffe.dataclasses import Alias, Module, Object +from griffe.enumerations import Kind from griffe.exceptions import AliasResolutionError, CyclicAliasError, LoadingError, UnimportableModuleError from griffe.expressions import ExprName -from griffe.extensions import Extensions +from griffe.extensions.base import Extensions from griffe.finder import ModuleFinder, NamespacePackage, Package from griffe.logger import get_logger from griffe.merger import merge_stubs @@ -33,7 +34,7 @@ if TYPE_CHECKING: from pathlib import Path - from griffe.docstrings.parsers import Parser + from griffe.enumerations import Parser logger = get_logger(__name__) _builtin_modules: set[str] = set(sys.builtin_module_names) diff --git a/src/griffe/tests.py b/src/griffe/tests.py index 9a1eabc3..ffc8486d 100644 --- a/src/griffe/tests.py +++ b/src/griffe/tests.py @@ -18,8 +18,8 @@ if TYPE_CHECKING: from griffe.collections import LinesCollection, ModulesCollection - from griffe.docstrings.parsers import Parser - from griffe.extensions import Extensions + from griffe.enumerations import Parser + from griffe.extensions.base import Extensions TMPDIR_PREFIX = "griffe_"