Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 52709:279e217d6041
typing: lock in the new type annotations detected with the pyupgrade changes
After the changes culminating in 70a75d379daf, pytype was able to detect these
types better (typically changing from something like `Generator[Any, Any, None]`
to `Generator[bytes, Any, None]`). Let's make these explicit so they don't
disappear because of other changes.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 06 Jan 2025 20:02:17 -0500 |
parents | e627cc25b6f3 |
children | 9b85f6efcc1d |
comparison
equal
deleted
inserted
replaced
52708:efac197c6cff | 52709:279e217d6041 |
---|---|
12 import contextlib | 12 import contextlib |
13 import copy | 13 import copy |
14 import os | 14 import os |
15 import re | 15 import re |
16 import shutil | 16 import shutil |
17 import typing | |
17 import zlib | 18 import zlib |
18 | 19 |
19 from .i18n import _ | 20 from .i18n import _ |
20 from .node import ( | 21 from .node import ( |
21 hex, | 22 hex, |
41 dateutil, | 42 dateutil, |
42 hashutil, | 43 hashutil, |
43 procutil, | 44 procutil, |
44 stringutil, | 45 stringutil, |
45 ) | 46 ) |
47 | |
48 if typing.TYPE_CHECKING: | |
49 from typing import ( | |
50 Any, | |
51 Iterator, | |
52 ) | |
46 | 53 |
47 stringio = util.stringio | 54 stringio = util.stringio |
48 | 55 |
49 gitre = re.compile(br'diff --git a/(.*) b/(.*)') | 56 gitre = re.compile(br'diff --git a/(.*) b/(.*)') |
50 tabsplitter = re.compile(br'(\t+|[^\t]+)') | 57 tabsplitter = re.compile(br'(\t+|[^\t]+)') |
2790 yield (endspaces, b'diff.trailingwhitespace') | 2797 yield (endspaces, b'diff.trailingwhitespace') |
2791 yield (endofline, b'') | 2798 yield (endofline, b'') |
2792 nextisnewline = True | 2799 nextisnewline = True |
2793 | 2800 |
2794 | 2801 |
2795 def difflabel(func, *args, **kw): | 2802 # TODO: first tuple element is likely bytes, but was being detected as bytes|int |
2803 # so it needs investigation/more typing here. | |
2804 def difflabel(func, *args, **kw) -> Iterator[tuple[Any, bytes]]: | |
2796 '''yields 2-tuples of (output, label) based on the output of func()''' | 2805 '''yields 2-tuples of (output, label) based on the output of func()''' |
2797 if kw.get('opts') and kw['opts'].worddiff: | 2806 if kw.get('opts') and kw['opts'].worddiff: |
2798 dodiffhunk = diffsinglehunkinline | 2807 dodiffhunk = diffsinglehunkinline |
2799 else: | 2808 else: |
2800 dodiffhunk = diffsinglehunk | 2809 dodiffhunk = diffsinglehunk |