Import typing as t ...

... and `collections.abc` as `cabc`

Linting rule for `velofy`: Import modules instead of objects
This commit is contained in:
Alexander Hess 2026-11-30 15:10:29 +01:00
commit 9c3b52befb
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -23,20 +23,19 @@ e.g., `uv run nox -s test -- tests/test_config.py`.
"""
import collections
import collections.abc as cabc
import itertools
import os
import pathlib
import tempfile
from collections.abc import Generator
from collections.abc import Mapping
from typing import Any
import typing as t
import nox
from nox.sessions import Session
from packaging import version as pkg_version
def nested_defaultdict() -> collections.defaultdict[str, Any]:
def nested_defaultdict() -> collections.defaultdict[str, t.Any]:
"""Create a multi-level `defaultdict` with variable depth.
The returned `dict`ionary never raises a `KeyError`
@ -48,9 +47,9 @@ def nested_defaultdict() -> collections.defaultdict[str, Any]:
return collections.defaultdict(nested_defaultdict)
def defaultify(obj: Any) -> Any:
def defaultify(obj: t.Any) -> t.Any:
"""Turn nested `dict`s into nested `defaultdict`s."""
if isinstance(obj, Mapping):
if isinstance(obj, cabc.Mapping):
return collections.defaultdict(
nested_defaultdict,
{key: defaultify(val) for key, val in obj.items()},
@ -58,7 +57,7 @@ def defaultify(obj: Any) -> Any:
return obj
def load_pyproject_toml() -> collections.defaultdict[str, Any]:
def load_pyproject_toml() -> collections.defaultdict[str, t.Any]:
"""Load the contents of the pyproject.toml file.
The contents are represented as a `nested_defaultdict`;
@ -522,7 +521,7 @@ def clean_cwd(session: Session) -> None:
session.run("rm", "-rf", path)
def _expand(*patterns: str) -> Generator[pathlib.Path, None, None]:
def _expand(*patterns: str) -> cabc.Generator[pathlib.Path, None, None]:
"""Expand glob patterns into (resolved) paths.
Args:
@ -600,7 +599,7 @@ def start(session: Session) -> None:
def install_pinned(
session: Session,
*packages_or_pip_args: str,
**kwargs: Any,
**kwargs: t.Any,
) -> None:
"""Install packages respecting the uv.lock file.