From 54e21ca2e5781fc49fc40554b4074c4b82ee04ca Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 3 May 2024 16:17:32 -0700 Subject: [PATCH] Add stubs for unidiff A pretty simple library. It has inline type comments, so stubgen was able to write most of the stubs for me. There is an open issue about switching to inline types (matiasb/python-unidiff#117). --- stubs/unidiff/METADATA.toml | 2 + stubs/unidiff/unidiff/__init__.pyi | 14 ++++ stubs/unidiff/unidiff/__version__.pyi | 1 + stubs/unidiff/unidiff/constants.pyi | 22 ++++++ stubs/unidiff/unidiff/errors.pyi | 1 + stubs/unidiff/unidiff/patch.pyi | 107 ++++++++++++++++++++++++++ 6 files changed, 147 insertions(+) create mode 100644 stubs/unidiff/METADATA.toml create mode 100644 stubs/unidiff/unidiff/__init__.pyi create mode 100644 stubs/unidiff/unidiff/__version__.pyi create mode 100644 stubs/unidiff/unidiff/constants.pyi create mode 100644 stubs/unidiff/unidiff/errors.pyi create mode 100644 stubs/unidiff/unidiff/patch.pyi diff --git a/stubs/unidiff/METADATA.toml b/stubs/unidiff/METADATA.toml new file mode 100644 index 000000000000..98f11c94dde3 --- /dev/null +++ b/stubs/unidiff/METADATA.toml @@ -0,0 +1,2 @@ +version = "0.7.*" +upstream_repository = "https://github.com/matiasb/python-unidiff" diff --git a/stubs/unidiff/unidiff/__init__.pyi b/stubs/unidiff/unidiff/__init__.pyi new file mode 100644 index 000000000000..db79ee8c7c4d --- /dev/null +++ b/stubs/unidiff/unidiff/__init__.pyi @@ -0,0 +1,14 @@ +from _typeshed import Incomplete + +from unidiff.patch import ( + DEFAULT_ENCODING as DEFAULT_ENCODING, + LINE_TYPE_ADDED as LINE_TYPE_ADDED, + LINE_TYPE_CONTEXT as LINE_TYPE_CONTEXT, + LINE_TYPE_REMOVED as LINE_TYPE_REMOVED, + Hunk as Hunk, + PatchedFile as PatchedFile, + PatchSet as PatchSet, + UnidiffParseError as UnidiffParseError, +) + +VERSION: Incomplete diff --git a/stubs/unidiff/unidiff/__version__.pyi b/stubs/unidiff/unidiff/__version__.pyi new file mode 100644 index 000000000000..bda5b5a7f4cc --- /dev/null +++ b/stubs/unidiff/unidiff/__version__.pyi @@ -0,0 +1 @@ +__version__: str diff --git a/stubs/unidiff/unidiff/constants.pyi b/stubs/unidiff/unidiff/constants.pyi new file mode 100644 index 000000000000..f9601dcea5bc --- /dev/null +++ b/stubs/unidiff/unidiff/constants.pyi @@ -0,0 +1,22 @@ +from re import Pattern + +RE_SOURCE_FILENAME: Pattern[str] +RE_TARGET_FILENAME: Pattern[str] +RE_DIFF_GIT_HEADER: Pattern[str] +RE_DIFF_GIT_HEADER_URI_LIKE: Pattern[str] +RE_DIFF_GIT_HEADER_NO_PREFIX: Pattern[str] +RE_DIFF_GIT_DELETED_FILE: Pattern[str] +RE_DIFF_GIT_NEW_FILE: Pattern[str] +RE_HUNK_HEADER: Pattern[str] +RE_HUNK_BODY_LINE: Pattern[str] +RE_HUNK_EMPTY_BODY_LINE: Pattern[str] +RE_NO_NEWLINE_MARKER: Pattern[str] +RE_BINARY_DIFF: Pattern[str] +DEFAULT_ENCODING: str +DEV_NULL: str +LINE_TYPE_ADDED: str +LINE_TYPE_REMOVED: str +LINE_TYPE_CONTEXT: str +LINE_TYPE_EMPTY: str +LINE_TYPE_NO_NEWLINE: str +LINE_VALUE_NO_NEWLINE: str diff --git a/stubs/unidiff/unidiff/errors.pyi b/stubs/unidiff/unidiff/errors.pyi new file mode 100644 index 000000000000..2904966569e1 --- /dev/null +++ b/stubs/unidiff/unidiff/errors.pyi @@ -0,0 +1 @@ +class UnidiffParseError(Exception): ... diff --git a/stubs/unidiff/unidiff/patch.pyi b/stubs/unidiff/unidiff/patch.pyi new file mode 100644 index 000000000000..f2f38f67c4ff --- /dev/null +++ b/stubs/unidiff/unidiff/patch.pyi @@ -0,0 +1,107 @@ +from _typeshed import StrPath +from collections.abc import Iterable +from typing import overload +from typing_extensions import Self + +class Line: + source_line_no: int | None + target_line_no: int | None + diff_line_no: int | None + line_type: str + value: str + def __init__( + self, + value: str, + line_type: str, + source_line_no: int | None = None, + target_line_no: int | None = None, + diff_line_no: int | None = None, + ) -> None: ... + def __eq__(self, other: Line) -> bool: ... + @property + def is_added(self) -> bool: ... + @property + def is_removed(self) -> bool: ... + @property + def is_context(self) -> bool: ... + +class PatchInfo(list[str]): ... + +class Hunk(list[Line]): + source_start: int + source_length: int + target_start: int + target_length: int + section_header: str + def __init__( + self, src_start: int = 0, src_len: int | None = 0, tgt_start: int = 0, tgt_len: int | None = 0, section_header: str = "" + ) -> None: ... + def append(self, line: Line) -> None: ... + @property + def added(self) -> int | None: ... + @property + def removed(self) -> int | None: ... + def is_valid(self) -> bool: ... + def source_lines(self) -> Iterable[Line]: ... + @property + def source(self) -> Iterable[str]: ... + def target_lines(self) -> Iterable[Line]: ... + @property + def target(self) -> Iterable[str]: ... + +class PatchedFile(list[Hunk]): + patch_info: PatchInfo | None + source_file: str + source_timestamp: str | None + target_file: str + target_timestamp: str | None + is_binary_file: bool + def __init__( + self, + patch_info: PatchInfo | None = None, + source: str = "", + target: str = "", + source_timestamp: str | None = None, + target_timestamp: str | None = None, + is_binary_file: bool = False, + ) -> None: ... + @property + def path(self) -> str: ... + @property + def added(self) -> int: ... + @property + def removed(self) -> int: ... + @property + def is_rename(self): ... + @property + def is_added_file(self) -> bool: ... + @property + def is_removed_file(self) -> bool: ... + @property + def is_modified_file(self) -> bool: ... + +class PatchSet(list[PatchedFile]): + @overload + def __init__(self, f: Iterable[str] | str, *, metadata_only: bool = False) -> None: ... + @overload + def __init__(self, f: Iterable[bytes] | bytes, encoding: str, metadata_only: bool = False) -> None: ... + @classmethod + def from_filename( + cls, filename: StrPath, encoding: str = "UTF-8", errors: str | None = None, newline: str | None = None + ) -> Self: ... + @classmethod + @overload + def from_string(cls, data: str, *, errors: str | None = "strict") -> Self: ... + @classmethod + @overload + def from_string(cls, data: bytes, encoding: str, errors: str | None = "strict") -> Self: ... + @property + def added_files(self) -> list[PatchedFile]: ... + @property + def removed_files(self) -> list[PatchedFile]: ... + @property + def modified_files(self) -> list[PatchedFile]: ... + @property + def added(self) -> int: ... + @property + def removed(self) -> int: ...