Add types for xmldiff (#14822)

This commit is contained in:
kasium
2025-10-07 15:22:04 +02:00
committed by GitHub
parent e057b9f97f
commit bc49fc5fe8
10 changed files with 331 additions and 0 deletions
+1
View File
@@ -92,6 +92,7 @@
"stubs/tqdm",
"stubs/vobject",
"stubs/workalendar",
"stubs/xmldiff",
],
"typeCheckingMode": "strict",
// TODO: Complete incomplete stubs
+2
View File
@@ -0,0 +1,2 @@
version = "2.7.*"
upstream_repository = "https://github.com/Shoobx/xmldiff"
View File
+58
View File
@@ -0,0 +1,58 @@
from _typeshed import Incomplete
from typing import NamedTuple
class DeleteNode(NamedTuple):
node: str
class InsertNode(NamedTuple):
target: Incomplete
tag: str
position: int
class RenameNode(NamedTuple):
node: str
tag: Incomplete
class MoveNode(NamedTuple):
node: str
target: Incomplete
position: int
class UpdateTextIn(NamedTuple):
node: str
text: Incomplete
class UpdateTextAfter(NamedTuple):
node: str
text: Incomplete
class UpdateAttrib(NamedTuple):
node: str
name: str
value: Incomplete
class DeleteAttrib(NamedTuple):
node: str
name: str
class InsertAttrib(NamedTuple):
node: str
name: str
value: Incomplete
class RenameAttrib(NamedTuple):
node: str
oldname: str
newname: str
class InsertComment(NamedTuple):
target: Incomplete
position: Incomplete
text: Incomplete
class InsertNamespace(NamedTuple):
prefix: str
uri: str
class DeleteNamespace(NamedTuple):
prefix: str
+36
View File
@@ -0,0 +1,36 @@
from _typeshed import Incomplete
from collections.abc import Generator
from typing import Literal
class Differ:
F: float
uniqueattrs: Incomplete
fast_match: Incomplete
best_match: Incomplete
ignored_attrs: Incomplete
def __init__(
self,
F: float | None = None,
uniqueattrs=None,
ratio_mode: Literal["accurate", "fast", "faster"] = "fast",
fast_match: bool = False,
best_match: bool = False,
ignored_attrs=[],
) -> None: ...
left: Incomplete
right: Incomplete
def clear(self) -> None: ...
def set_trees(self, left, right) -> None: ...
def append_match(self, lnode, rnode, max_match) -> None: ...
def match(self, left=None, right=None): ...
def node_ratio(self, left, right): ...
def node_text(self, node): ...
def node_attribs(self, node): ...
def leaf_ratio(self, left, right): ...
def child_ratio(self, left, right): ...
def update_node_tag(self, left, right) -> Generator[Incomplete]: ...
def update_node_attr(self, left, right) -> Generator[Incomplete]: ...
def update_node_text(self, left, right) -> Generator[Incomplete]: ...
def find_pos(self, node): ...
def align_children(self, left, right) -> Generator[Incomplete, None, Incomplete]: ...
def diff(self, left=None, right=None) -> Generator[Incomplete, Incomplete]: ...
@@ -0,0 +1,58 @@
from _typeshed import Incomplete
class diff_match_patch:
Diff_Timeout: float
Diff_EditCost: int
Match_Threshold: float
Match_Distance: int
Patch_DeleteThreshold: float
Patch_Margin: int
Match_MaxBits: int
def __init__(self) -> None: ...
DIFF_DELETE: int
DIFF_INSERT: int
DIFF_EQUAL: int
DIFF_REPLACE: int
def diff_main(self, text1, text2, checklines: bool = True, deadline=None): ...
def diff_compute(self, text1, text2, checklines, deadline): ...
def diff_lineMode(self, text1, text2, deadline): ...
def diff_bisect(self, text1, text2, deadline): ...
def diff_bisectSplit(self, text1, text2, x, y, deadline): ...
def diff_linesToChars(self, text1, text2): ...
def diff_charsToLines(self, diffs, lineArray) -> None: ...
def diff_commonPrefix(self, text1, text2): ...
def diff_commonSuffix(self, text1, text2): ...
def diff_commonOverlap(self, text1, text2): ...
def diff_halfMatch(self, text1, text2): ...
def diff_cleanupSemantic(self, diffs) -> None: ...
def diff_cleanupSemanticLossless(self, diffs): ...
BLANKLINEEND: Incomplete
BLANKLINESTART: Incomplete
def diff_cleanupEfficiency(self, diffs) -> None: ...
def diff_cleanupMerge(self, diffs) -> None: ...
def diff_xIndex(self, diffs, loc): ...
def diff_prettyHtml(self, diffs): ...
def diff_text1(self, diffs): ...
def diff_text2(self, diffs): ...
def diff_levenshtein(self, diffs): ...
def diff_toDelta(self, diffs): ...
def diff_fromDelta(self, text1, delta): ...
def match_main(self, text, pattern, loc): ...
def match_bitap(self, text, pattern, loc): ...
def match_alphabet(self, pattern): ...
def patch_addContext(self, patch, text) -> None: ...
def patch_make(self, a, b=None, c=None): ...
def patch_deepCopy(self, patches): ...
def patch_apply(self, patches, text): ...
def patch_addPadding(self, patches): ...
def patch_splitMax(self, patches) -> None: ...
def patch_toText(self, patches): ...
def patch_fromText(self, textline): ...
class patch_obj:
diffs: Incomplete
start1: Incomplete
start2: Incomplete
length1: int
length2: int
def __init__(self) -> None: ...
+80
View File
@@ -0,0 +1,80 @@
from _typeshed import Incomplete
from collections.abc import Generator
from typing import Final, NamedTuple
DIFF_NS: Final[str]
DIFF_PREFIX: Final[str]
INSERT_NAME: Final[Incomplete]
DELETE_NAME: Final[Incomplete]
REPLACE_NAME: Final[Incomplete]
RENAME_NAME: Final[Incomplete]
WS_BOTH: Final[int]
WS_TEXT: Final[int]
WS_TAGS: Final[int]
WS_NONE: Final[int]
T_OPEN: Final[int]
T_CLOSE: Final[int]
T_SINGLE: Final[int]
PLACEHOLDER_START: Final[int]
class BaseFormatter:
def __init__(self, normalize=1, pretty_print: bool = False) -> None: ...
def prepare(self, left_tree, right_tree) -> None: ...
def format(self, diff, orig_tree) -> None: ...
class PlaceholderEntry(NamedTuple):
element: Incomplete
ttype: Incomplete
close_ph: Incomplete
class PlaceholderMaker:
text_tags: Incomplete
formatting_tags: Incomplete
placeholder2tag: Incomplete
tag2placeholder: Incomplete
placeholder: Incomplete
diff_tags: Incomplete
def __init__(self, text_tags=(), formatting_tags=()) -> None: ...
def get_placeholder(self, element, ttype, close_ph): ...
def is_placeholder(self, char): ...
def is_formatting(self, element): ...
def do_element(self, element) -> None: ...
def do_tree(self, tree) -> None: ...
def split_string(self, text): ...
def undo_string(self, text): ...
def undo_element(self, elem) -> None: ...
def undo_tree(self, tree) -> None: ...
def mark_diff(self, ph, action, attributes=None): ...
def wrap_diff(self, text, action, attributes=None): ...
class XMLFormatter(BaseFormatter):
normalize: Incomplete
pretty_print: Incomplete
text_tags: Incomplete
formatting_tags: Incomplete
use_replace: Incomplete
placeholderer: Incomplete
def __init__(
self, normalize=0, pretty_print: bool = True, text_tags=(), formatting_tags=(), use_replace: bool = False
) -> None: ...
def prepare(self, left_tree, right_tree) -> None: ...
def finalize(self, result_tree) -> None: ...
def format(self, diff, orig_tree, differ=None): ...
def render(self, result): ...
def handle_action(self, action, result) -> None: ...
class DiffFormatter(BaseFormatter):
normalize: Incomplete
def __init__(self, normalize=1, pretty_print: bool = False) -> None: ...
def prepare(self, left, right) -> None: ...
def finalize(self, left, right) -> None: ...
def format(self, diff, orig_tree): ...
def handle_action(self, action): ...
class XmlDiffFormatter(BaseFormatter):
normalize: Incomplete
def __init__(self, normalize=1, pretty_print: bool = False) -> None: ...
def prepare(self, left, right) -> None: ...
def finalize(self, left, right) -> None: ...
def format(self, diff, orig_tree): ...
def handle_action(self, action, orig_tree) -> Generator[Incomplete, Incomplete]: ...
+68
View File
@@ -0,0 +1,68 @@
from argparse import ArgumentParser
from collections.abc import Iterable, Mapping, Sequence
from typing import Any, overload
from typing_extensions import TypeAlias
from xmldiff.actions import (
DeleteAttrib,
DeleteNamespace,
DeleteNode,
InsertAttrib,
InsertComment,
InsertNamespace,
InsertNode,
MoveNode,
RenameAttrib,
RenameNode,
UpdateAttrib,
UpdateTextAfter,
UpdateTextIn,
)
from xmldiff.formatting import BaseFormatter
__version__: str
FORMATTERS: Mapping[str, BaseFormatter]
_ACTIONS: TypeAlias = (
DeleteNode
| InsertNode
| RenameNode
| MoveNode
| UpdateTextIn
| UpdateTextAfter
| UpdateAttrib
| DeleteAttrib
| InsertAttrib
| RenameAttrib
| InsertComment
| InsertNamespace
| DeleteNamespace
)
_ET: TypeAlias = Any # lxml.etree._ElementTree
@overload
def diff_trees(left: _ET, right: _ET, *, diff_options: dict[str, Any] | None = None, formatter: BaseFormatter = ...) -> str: ...
@overload
def diff_trees(
left: _ET, right: _ET, diff_options: dict[str, Any] | None = None, formatter: None = None
) -> Iterable[_ACTIONS]: ...
@overload
def diff_texts(left: str, right: str, *, diff_options: dict[str, Any] | None = None, formatter: BaseFormatter = ...) -> str: ...
@overload
def diff_texts(
left: str, right: str, diff_options: dict[str, Any] | None = None, formatter: None = None
) -> Iterable[_ACTIONS]: ...
@overload
def diff_files(left: str, right: str, *, diff_options: dict[str, Any] | None = None, formatter: BaseFormatter = ...) -> str: ...
@overload
def diff_files(
left: str, right: str, diff_options: dict[str, Any] | None = None, formatter: None = None
) -> Iterable[_ACTIONS]: ...
def validate_F(arg: float | str) -> float: ...
def make_diff_parser() -> ArgumentParser: ...
def diff_command(args: Sequence[str] | None = None) -> int | None: ...
def patch_tree(actions, tree): ...
def patch_text(actions, tree): ...
def patch_file(actions, tree, diff_encoding=None): ...
def make_patch_parser(): ...
def patch_command(args=None) -> None: ...
+12
View File
@@ -0,0 +1,12 @@
from _typeshed import Incomplete
from collections.abc import Generator
class Patcher:
@property
def nsmap(self): ...
def patch(self, actions, tree): ...
def handle_action(self, action, tree) -> None: ...
class DiffParser:
def parse(self, diff) -> Generator[Incomplete]: ...
def make_action(self, line): ...
+16
View File
@@ -0,0 +1,16 @@
from _typeshed import Incomplete
from collections.abc import Generator
from re import Pattern
RESERVED_NS: Pattern[str]
def post_order_traverse(node) -> Generator[Incomplete, Incomplete]: ...
def reverse_post_order_traverse(node) -> Generator[Incomplete, Incomplete]: ...
def breadth_first_traverse(node) -> Generator[Incomplete]: ...
def longest_common_subsequence(left_sequence, right_sequence, eqfn=...): ...
WHITESPACE: Incomplete
def cleanup_whitespace(text): ...
def getpath(element, tree=None): ...
def make_ascii_tree(element): ...