Skip to content

Commit

Permalink
test: satisfy updated linters
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Oct 17, 2024
1 parent f29d7f6 commit ac51fd0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/darker/black_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
based on whether reformats touch user-edited lines
"""

from __future__ import annotations

import inspect
import logging
from pathlib import Path
from typing import Collection, Optional, Pattern, Set, Tuple, TypedDict, Union
from typing import TYPE_CHECKING, Collection, Pattern, TypedDict

# `FileMode as Mode` required to satisfy mypy==0.782. Strange.
from black import FileMode as Mode
Expand All @@ -56,6 +58,9 @@
from darkgraylib.config import ConfigurationError
from darkgraylib.utils import TextDocument

if TYPE_CHECKING:
from pathlib import Path

__all__ = ["BlackConfig", "Mode", "run_black"]

logger = logging.getLogger(__name__)
Expand All @@ -69,10 +74,10 @@ class BlackConfig(TypedDict, total=False):
"""Type definition for Black configuration dictionaries"""

config: str
exclude: Pattern[str]
extend_exclude: Pattern[str]
force_exclude: Pattern[str]
target_version: Union[str, Set[str]]
exclude: Pattern[str] | None
extend_exclude: Pattern[str] | None
force_exclude: Pattern[str] | None
target_version: str | set[str]
line_length: int
skip_string_normalization: bool
skip_magic_trailing_comma: bool
Expand All @@ -82,15 +87,15 @@ class BlackConfig(TypedDict, total=False):
class BlackModeAttributes(TypedDict, total=False):
"""Type definition for items accepted by ``black.Mode``"""

target_versions: Set[TargetVersion]
target_versions: set[TargetVersion]
line_length: int
string_normalization: bool
is_pyi: bool
magic_trailing_comma: bool
preview: bool


def read_black_config(src: Tuple[str, ...], value: Optional[str]) -> BlackConfig:
def read_black_config(src: tuple[str, ...], value: str | None) -> BlackConfig:
"""Read the black configuration from ``pyproject.toml``
:param src: The source code files and directories to be processed by Darker
Expand Down Expand Up @@ -136,7 +141,7 @@ def filter_python_files(
paths: Collection[Path], # pylint: disable=unsubscriptable-object
root: Path,
black_config: BlackConfig,
) -> Set[Path]:
) -> set[Path]:
"""Get Python files and explicitly listed files not excluded by Black's config
:param paths: Relative file/directory paths from CWD to Python sources
Expand Down Expand Up @@ -164,7 +169,7 @@ def filter_python_files(
directories,
root,
include=DEFAULT_INCLUDE_RE,
exclude=black_config.get("exclude", DEFAULT_EXCLUDE_RE),
exclude=black_config.get("exclude") or DEFAULT_EXCLUDE_RE,
extend_exclude=black_config.get("extend_exclude"),
force_exclude=black_config.get("force_exclude"),
report=Report(),
Expand Down

0 comments on commit ac51fd0

Please sign in to comment.