Skip to content

Commit

Permalink
style: modernize config.py and satisfy linters
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Sep 25, 2024
1 parent a3b2cc4 commit c5f6a13
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions constraints-oldest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ ruamel.yaml==0.17.21
toml==0.10.0
twine==2.0.0
types-toml==0.10.4
typing_extensions==4.0.1
wheel==0.21.0
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ select = ["ALL"]
ignore = [
"A002", # builtin-argument-shadowing
"ANN101", # Missing type annotation for `self` in method
"COM812", # Trailing comma missing
"D203", # One blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D400", # First line should end with a period (duplicates D415)
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ install_requires =
black>=22.3.0
darkgraylib~=2.0.1
toml>=0.10.0
typing_extensions>=4.0.1
# NOTE: remember to keep `.github/workflows/python-package.yml` in sync
# with the minimum required Python version
python_requires = >=3.8
Expand Down
2 changes: 1 addition & 1 deletion src/darker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def main( # noqa: C901,PLR0912,PLR0915
# Make sure there aren't invalid option combinations after merging configuration and
# command line options.
OutputMode.validate_diff_stdout(args.diff, args.stdout)
OutputMode.validate_stdout_src(args.stdout, args.src, args.stdin_filename)
OutputMode.validate_stdout_src(args.src, args.stdin_filename, stdout=args.stdout)
validate_config_output_mode(config)

setup_logging(args.log_level)
Expand Down
2 changes: 1 addition & 1 deletion src/darker/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ def parse_command_line(
show_config_deprecations,
)
OutputMode.validate_diff_stdout(args.diff, args.stdout)
OutputMode.validate_stdout_src(args.stdout, args.src, args.stdin_filename)
OutputMode.validate_stdout_src(args.src, args.stdin_filename, stdout=args.stdout)
return args, effective_cfg, modified_cfg
24 changes: 16 additions & 8 deletions src/darker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

from __future__ import annotations

from argparse import Namespace
import sys
from dataclasses import dataclass, field
from pathlib import Path
from typing import Dict, List, Optional, Set, Union
from typing import TYPE_CHECKING, Dict, List, Union

from darkgraylib.config import BaseConfig, ConfigurationError

UnvalidatedConfig = Dict[str, Union[List[str], str, bool, int]]
if TYPE_CHECKING:
from argparse import Namespace

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias

UnvalidatedConfig: TypeAlias = Dict[str, Union[List[str], str, bool, int]]


REMOVED_CONFIG_OPTIONS = {
Expand All @@ -31,7 +39,7 @@ class DarkerConfig(BaseConfig, total=False):
diff: bool
check: bool
isort: bool
lint: List[str]
lint: list[str]
skip_string_normalization: bool
skip_magic_trailing_comma: bool
line_length: int
Expand Down Expand Up @@ -65,7 +73,7 @@ def validate_diff_stdout(diff: bool, stdout: bool) -> None:

@staticmethod
def validate_stdout_src(
stdout: bool, src: List[str], stdin_filename: Optional[str]
src: list[str], stdin_filename: str | None, *, stdout: bool
) -> None:
"""Raise an exception in ``stdout`` mode if not exactly one input is provided"""
if not stdout:
Expand Down Expand Up @@ -104,6 +112,6 @@ class Exclusions:
"""

black: Set[str] = field(default_factory=set)
isort: Set[str] = field(default_factory=set)
flynt: Set[str] = field(default_factory=set)
black: set[str] = field(default_factory=set)
isort: set[str] = field(default_factory=set)
flynt: set[str] = field(default_factory=set)
3 changes: 1 addition & 2 deletions src/darker/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def test_output_mode_validate_stdout_src(
Path("first.py").touch()
Path("second.py").touch()
with raises_if_exception(expect):

OutputMode.validate_stdout_src(stdout, src, stdin_filename)
OutputMode.validate_stdout_src(src, stdin_filename, stdout=stdout)


@pytest.mark.kwparametrize(
Expand Down

0 comments on commit c5f6a13

Please sign in to comment.