Skip to content

Commit

Permalink
Add stubs for whatthepatch (#7492)
Browse files Browse the repository at this point in the history
Co-authored-by: Akuli <akuviljanen17@gmail.com>
  • Loading branch information
cuspymd and Akuli authored Mar 16, 2022
1 parent ec8f517 commit 830b57f
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions stubs/whatthepatch/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.0.*"
2 changes: 2 additions & 0 deletions stubs/whatthepatch/whatthepatch/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .apply import apply_diff as apply_diff
from .patch import parse_patch as parse_patch
8 changes: 8 additions & 0 deletions stubs/whatthepatch/whatthepatch/apply.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from collections.abc import Iterable

from . import patch as patch
from .exceptions import HunkApplyException as HunkApplyException, SubprocessException as SubprocessException
from .snippets import remove as remove, which as which

def apply_patch(diffs: patch.diffobj | Iterable[patch.diffobj]) -> None: ...
def apply_diff(diff: patch.diffobj, text: str | Iterable[str], reverse: bool = ..., use_patch: bool = ...) -> list[str]: ...
14 changes: 14 additions & 0 deletions stubs/whatthepatch/whatthepatch/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class WhatThePatchException(Exception): ...

class HunkException(WhatThePatchException):
hunk: int | None
def __init__(self, msg: str, hunk: int | None = ...) -> None: ...

class ApplyException(WhatThePatchException): ...

class SubprocessException(ApplyException):
code: int
def __init__(self, msg: str, code: int) -> None: ...

class HunkApplyException(HunkException, ApplyException, ValueError): ...
class ParseException(HunkException, ValueError): ...
77 changes: 77 additions & 0 deletions stubs/whatthepatch/whatthepatch/patch.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from collections.abc import Iterable, Iterator
from typing import NamedTuple, Pattern

from . import exceptions as exceptions
from .snippets import findall_regex as findall_regex, split_by_regex as split_by_regex

class header(NamedTuple):
index_path: str | None
old_path: str
old_version: str | None
new_path: str
new_version: str | None

class diffobj(NamedTuple):
header: header | None
changes: list[Change] | None
text: str

class Change(NamedTuple):
old: int | None
new: int | None
line: int | None
hunk: int

file_timestamp_str: str
diffcmd_header: Pattern[str]
unified_header_index: Pattern[str]
unified_header_old_line: Pattern[str]
unified_header_new_line: Pattern[str]
unified_hunk_start: Pattern[str]
unified_change: Pattern[str]
context_header_old_line: Pattern[str]
context_header_new_line: Pattern[str]
context_hunk_start: Pattern[str]
context_hunk_old: Pattern[str]
context_hunk_new: Pattern[str]
context_change: Pattern[str]
ed_hunk_start: Pattern[str]
ed_hunk_end: Pattern[str]
rcs_ed_hunk_start: Pattern[str]
default_hunk_start: Pattern[str]
default_hunk_mid: Pattern[str]
default_change: Pattern[str]
git_diffcmd_header: Pattern[str]
git_header_index: Pattern[str]
git_header_old_line: Pattern[str]
git_header_new_line: Pattern[str]
git_header_file_mode: Pattern[str]
git_header_binary_file: Pattern[str]
bzr_header_index: Pattern[str]
bzr_header_old_line: Pattern[str]
bzr_header_new_line: Pattern[str]
svn_header_index: Pattern[str]
svn_header_timestamp_version: Pattern[str]
svn_header_timestamp: Pattern[str]
cvs_header_index: Pattern[str]
cvs_header_rcs: Pattern[str]
cvs_header_timestamp: Pattern[str]
cvs_header_timestamp_colon: Pattern[str]
old_cvs_diffcmd_header: Pattern[str]

def parse_patch(text: str | Iterable[str]) -> Iterator[diffobj]: ...
def parse_header(text: str | Iterable[str]) -> header | None: ...
def parse_scm_header(text: str | Iterable[str]) -> header | None: ...
def parse_diff_header(text: str | Iterable[str]) -> header | None: ...
def parse_diff(text: str | Iterable[str]) -> list[Change] | None: ...
def parse_git_header(text: str | Iterable[str]) -> header | None: ...
def parse_svn_header(text: str | Iterable[str]) -> header | None: ...
def parse_cvs_header(text: str | Iterable[str]) -> header | None: ...
def parse_diffcmd_header(text: str | Iterable[str]) -> header | None: ...
def parse_unified_header(text: str | Iterable[str]) -> header | None: ...
def parse_context_header(text: str | Iterable[str]) -> header | None: ...
def parse_default_diff(text: str | Iterable[str]) -> list[Change] | None: ...
def parse_unified_diff(text: str | Iterable[str]) -> list[Change] | None: ...
def parse_context_diff(text: str | Iterable[str]) -> list[Change] | None: ...
def parse_ed_diff(text: str | Iterable[str]) -> list[Change] | None: ...
def parse_rcs_ed_diff(text: str | Iterable[str]) -> list[Change] | None: ...
7 changes: 7 additions & 0 deletions stubs/whatthepatch/whatthepatch/snippets.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from collections.abc import Sequence
from typing import Pattern

def remove(path: str) -> None: ...
def findall_regex(items: Sequence[str], regex: Pattern[str]) -> list[int]: ...
def split_by_regex(items: Sequence[str], regex: Pattern[str]) -> list[Sequence[str]]: ...
def which(program: str) -> str | None: ...

0 comments on commit 830b57f

Please sign in to comment.