Skip to content

Commit

Permalink
Merge pull request #599 from akaihola/diff-typing
Browse files Browse the repository at this point in the history
Adjust typing in `diff.py` to match Darkgraylib
  • Loading branch information
akaihola authored Jul 29, 2024
2 parents f5f3fe7 + 2853661 commit 2eb092e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion constraints-oldest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# interpreter and Python ependencies. Keep this up-to-date with minimum
# versions in `setup.cfg`.
black==22.3.0
darkgraylib==1.3.1
darkgraylib==1.3.2
defusedxml==0.7.1
flake8-2020==1.6.1
flake8-bugbear==22.1.11
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ packages = find:
install_requires =
# NOTE: remember to keep `constraints-oldest.txt` in sync with these
black>=22.3.0
darkgraylib~=1.3.1
darkgraylib~=1.3.2
graylint~=1.1.2
toml>=0.10.0
# NOTE: remember to keep `.github/workflows/python-package.yml` in sync
Expand Down
10 changes: 7 additions & 3 deletions src/darker/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"""

import logging
from typing import Generator, List, Sequence, Tuple
from typing import Generator, List, Literal, Sequence, Tuple

from darker.multiline_strings import find_overlap
from darkgraylib.diff import diff_and_get_opcodes, validate_opcodes
Expand All @@ -75,7 +75,9 @@


def opcodes_to_edit_linenums( # pylint: disable=too-many-locals
opcodes: List[Tuple[str, int, int, int, int]],
opcodes: List[
Tuple[Literal["replace", "delete", "insert", "equal"], int, int, int, int]
],
context_lines: int,
multiline_string_ranges: Sequence[Tuple[int, int]],
) -> Generator[int, None, None]:
Expand Down Expand Up @@ -123,7 +125,9 @@ def opcodes_to_edit_linenums( # pylint: disable=too-many-locals


def opcodes_to_chunks(
opcodes: List[Tuple[str, int, int, int, int]],
opcodes: List[
Tuple[Literal["replace", "delete", "insert", "equal"], int, int, int, int]
],
src: TextDocument,
dst: TextDocument,
) -> Generator[DiffChunk, None, None]:
Expand Down
10 changes: 5 additions & 5 deletions src/darker/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
# pylint: disable=use-dict-literal

from itertools import chain
from typing import List, Literal, Tuple

import pytest

from darker.diff import (
opcodes_to_chunks,
opcodes_to_edit_linenums,
)
from darker.diff import opcodes_to_chunks, opcodes_to_edit_linenums
from darkgraylib.testtools.diff_helpers import (
EXPECT_OPCODES,
FUNCTIONS2_PY,
Expand Down Expand Up @@ -98,7 +96,9 @@ def test_opcodes_to_chunks():
]


EXAMPLE_OPCODES = [
EXAMPLE_OPCODES: List[
Tuple[Literal["replace", "delete", "insert", "equal"], int, int, int, int]
] = [
# 0-based, end-exclusive
("replace", 0, 4, 0, 1),
("equal", 4, 6, 1, 3),
Expand Down

0 comments on commit 2eb092e

Please sign in to comment.