Skip to content

Commit

Permalink
refactor: Use canonical imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Feb 12, 2024
1 parent 6fe1316 commit 3091660
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 59 deletions.
7 changes: 5 additions & 2 deletions src/griffe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 6 additions & 14 deletions src/griffe/agents/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion src/griffe/agents/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 13 additions & 18 deletions src/griffe/agents/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions src/griffe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/griffe/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/griffe/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/griffe/docstrings/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion src/griffe/docstrings/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
DocstringSectionDeprecated,
DocstringSectionExamples,
DocstringSectionFunctions,
DocstringSectionKind,
DocstringSectionModules,
DocstringSectionOtherParameters,
DocstringSectionParameters,
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/griffe/docstrings/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
DocstringSectionDeprecated,
DocstringSectionExamples,
DocstringSectionFunctions,
DocstringSectionKind,
DocstringSectionModules,
DocstringSectionOtherParameters,
DocstringSectionParameters,
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/griffe/docstrings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions src/griffe/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/griffe/extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
)

Expand Down
3 changes: 2 additions & 1 deletion src/griffe/extensions/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/griffe/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-"
Expand Down
7 changes: 4 additions & 3 deletions src/griffe/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/griffe/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_"

Expand Down

0 comments on commit 3091660

Please sign in to comment.