Skip to content

Commit 23e298f

Browse files
committed
Add types for xmldiff
1 parent e6f5183 commit 23e298f

File tree

10 files changed

+333
-0
lines changed

10 files changed

+333
-0
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"stubs/tqdm",
9393
"stubs/vobject",
9494
"stubs/workalendar",
95+
"stubs/xmldiff",
9596
],
9697
"typeCheckingMode": "strict",
9798
// TODO: Complete incomplete stubs

stubs/xmldiff/METADATA.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "2.7.*"
2+
upstream_repository = "https://github.com/Shoobx/xmldiff"
3+
requires = ["lxml"]

stubs/xmldiff/xmldiff/__init__.pyi

Whitespace-only changes.

stubs/xmldiff/xmldiff/actions.pyi

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from _typeshed import Incomplete
2+
from typing import NamedTuple
3+
4+
class DeleteNode(NamedTuple):
5+
node: str
6+
7+
class InsertNode(NamedTuple):
8+
target: Incomplete
9+
tag: str
10+
position: int
11+
12+
class RenameNode(NamedTuple):
13+
node: str
14+
tag: Incomplete
15+
16+
class MoveNode(NamedTuple):
17+
node: str
18+
target: Incomplete
19+
position: int
20+
21+
class UpdateTextIn(NamedTuple):
22+
node: str
23+
text: Incomplete
24+
25+
class UpdateTextAfter(NamedTuple):
26+
node: str
27+
text: Incomplete
28+
29+
class UpdateAttrib(NamedTuple):
30+
node: str
31+
name: str
32+
value: Incomplete
33+
34+
class DeleteAttrib(NamedTuple):
35+
node: str
36+
name: str
37+
38+
class InsertAttrib(NamedTuple):
39+
node: str
40+
name: str
41+
value: Incomplete
42+
43+
class RenameAttrib(NamedTuple):
44+
node: str
45+
oldname: str
46+
newname: str
47+
48+
class InsertComment(NamedTuple):
49+
target: Incomplete
50+
position: Incomplete
51+
text: Incomplete
52+
53+
class InsertNamespace(NamedTuple):
54+
prefix: str
55+
uri: str
56+
57+
class DeleteNamespace(NamedTuple):
58+
prefix: str

stubs/xmldiff/xmldiff/diff.pyi

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Generator
3+
4+
class Differ:
5+
F: float
6+
uniqueattrs: Incomplete
7+
fast_match: Incomplete
8+
best_match: Incomplete
9+
ignored_attrs: Incomplete
10+
def __init__(
11+
self,
12+
F: float | None = None,
13+
uniqueattrs=None,
14+
ratio_mode: str = "fast",
15+
fast_match: bool = False,
16+
best_match: bool = False,
17+
ignored_attrs=[],
18+
) -> None: ...
19+
left: Incomplete
20+
right: Incomplete
21+
def clear(self) -> None: ...
22+
def set_trees(self, left, right) -> None: ...
23+
def append_match(self, lnode, rnode, max_match) -> None: ...
24+
def match(self, left=None, right=None): ...
25+
def node_ratio(self, left, right): ...
26+
def node_text(self, node): ...
27+
def node_attribs(self, node): ...
28+
def leaf_ratio(self, left, right): ...
29+
def child_ratio(self, left, right): ...
30+
def update_node_tag(self, left, right) -> Generator[Incomplete]: ...
31+
def update_node_attr(self, left, right) -> Generator[Incomplete]: ...
32+
def update_node_text(self, left, right) -> Generator[Incomplete]: ...
33+
def find_pos(self, node): ...
34+
def align_children(self, left, right) -> Generator[Incomplete, None, Incomplete]: ...
35+
def diff(self, left=None, right=None) -> Generator[Incomplete, Incomplete]: ...
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from _typeshed import Incomplete
2+
3+
class diff_match_patch:
4+
Diff_Timeout: float
5+
Diff_EditCost: int
6+
Match_Threshold: float
7+
Match_Distance: int
8+
Patch_DeleteThreshold: float
9+
Patch_Margin: int
10+
Match_MaxBits: int
11+
def __init__(self) -> None: ...
12+
DIFF_DELETE: int
13+
DIFF_INSERT: int
14+
DIFF_EQUAL: int
15+
DIFF_REPLACE: int
16+
def diff_main(self, text1, text2, checklines: bool = True, deadline=None): ...
17+
def diff_compute(self, text1, text2, checklines, deadline): ...
18+
def diff_lineMode(self, text1, text2, deadline): ...
19+
def diff_bisect(self, text1, text2, deadline): ...
20+
def diff_bisectSplit(self, text1, text2, x, y, deadline): ...
21+
def diff_linesToChars(self, text1, text2): ...
22+
def diff_charsToLines(self, diffs, lineArray) -> None: ...
23+
def diff_commonPrefix(self, text1, text2): ...
24+
def diff_commonSuffix(self, text1, text2): ...
25+
def diff_commonOverlap(self, text1, text2): ...
26+
def diff_halfMatch(self, text1, text2): ...
27+
def diff_cleanupSemantic(self, diffs) -> None: ...
28+
def diff_cleanupSemanticLossless(self, diffs): ...
29+
BLANKLINEEND: Incomplete
30+
BLANKLINESTART: Incomplete
31+
def diff_cleanupEfficiency(self, diffs) -> None: ...
32+
def diff_cleanupMerge(self, diffs) -> None: ...
33+
def diff_xIndex(self, diffs, loc): ...
34+
def diff_prettyHtml(self, diffs): ...
35+
def diff_text1(self, diffs): ...
36+
def diff_text2(self, diffs): ...
37+
def diff_levenshtein(self, diffs): ...
38+
def diff_toDelta(self, diffs): ...
39+
def diff_fromDelta(self, text1, delta): ...
40+
def match_main(self, text, pattern, loc): ...
41+
def match_bitap(self, text, pattern, loc): ...
42+
def match_alphabet(self, pattern): ...
43+
def patch_addContext(self, patch, text) -> None: ...
44+
def patch_make(self, a, b=None, c=None): ...
45+
def patch_deepCopy(self, patches): ...
46+
def patch_apply(self, patches, text): ...
47+
def patch_addPadding(self, patches): ...
48+
def patch_splitMax(self, patches) -> None: ...
49+
def patch_toText(self, patches): ...
50+
def patch_fromText(self, textline): ...
51+
52+
class patch_obj:
53+
diffs: Incomplete
54+
start1: Incomplete
55+
start2: Incomplete
56+
length1: int
57+
length2: int
58+
def __init__(self) -> None: ...
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Generator
3+
from typing import NamedTuple
4+
5+
DIFF_NS: str
6+
DIFF_PREFIX: str
7+
INSERT_NAME: Incomplete
8+
DELETE_NAME: Incomplete
9+
REPLACE_NAME: Incomplete
10+
RENAME_NAME: Incomplete
11+
WS_BOTH: int
12+
WS_TEXT: int
13+
WS_TAGS: int
14+
WS_NONE: int
15+
T_OPEN: int
16+
T_CLOSE: int
17+
T_SINGLE: int
18+
PLACEHOLDER_START: int
19+
20+
class BaseFormatter:
21+
def __init__(self, normalize=1, pretty_print: bool = False) -> None: ...
22+
def prepare(self, left_tree, right_tree) -> None: ...
23+
def format(self, diff, orig_tree) -> None: ...
24+
25+
class PlaceholderEntry(NamedTuple):
26+
element: Incomplete
27+
ttype: Incomplete
28+
close_ph: Incomplete
29+
30+
class PlaceholderMaker:
31+
text_tags: Incomplete
32+
formatting_tags: Incomplete
33+
placeholder2tag: Incomplete
34+
tag2placeholder: Incomplete
35+
placeholder: Incomplete
36+
diff_tags: Incomplete
37+
def __init__(self, text_tags=(), formatting_tags=()) -> None: ...
38+
def get_placeholder(self, element, ttype, close_ph): ...
39+
def is_placeholder(self, char): ...
40+
def is_formatting(self, element): ...
41+
def do_element(self, element) -> None: ...
42+
def do_tree(self, tree) -> None: ...
43+
def split_string(self, text): ...
44+
def undo_string(self, text): ...
45+
def undo_element(self, elem) -> None: ...
46+
def undo_tree(self, tree) -> None: ...
47+
def mark_diff(self, ph, action, attributes=None): ...
48+
def wrap_diff(self, text, action, attributes=None): ...
49+
50+
class XMLFormatter(BaseFormatter):
51+
normalize: Incomplete
52+
pretty_print: Incomplete
53+
text_tags: Incomplete
54+
formatting_tags: Incomplete
55+
use_replace: Incomplete
56+
placeholderer: Incomplete
57+
def __init__(
58+
self, normalize=0, pretty_print: bool = True, text_tags=(), formatting_tags=(), use_replace: bool = False
59+
) -> None: ...
60+
def prepare(self, left_tree, right_tree) -> None: ...
61+
def finalize(self, result_tree) -> None: ...
62+
def format(self, diff, orig_tree, differ=None): ...
63+
def render(self, result): ...
64+
def handle_action(self, action, result) -> None: ...
65+
66+
class DiffFormatter(BaseFormatter):
67+
normalize: Incomplete
68+
def __init__(self, normalize=1, pretty_print: bool = False) -> None: ...
69+
def prepare(self, left, right) -> None: ...
70+
def finalize(self, left, right) -> None: ...
71+
def format(self, diff, orig_tree): ...
72+
def handle_action(self, action): ...
73+
74+
class XmlDiffFormatter(BaseFormatter):
75+
normalize: Incomplete
76+
def __init__(self, normalize=1, pretty_print: bool = False) -> None: ...
77+
def prepare(self, left, right) -> None: ...
78+
def finalize(self, left, right) -> None: ...
79+
def format(self, diff, orig_tree): ...
80+
def handle_action(self, action, orig_tree) -> Generator[Incomplete, Incomplete]: ...

stubs/xmldiff/xmldiff/main.pyi

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from argparse import ArgumentParser
2+
from collections.abc import Iterable, Mapping, Sequence
3+
from typing import Any, overload
4+
from typing_extensions import TypeAlias
5+
6+
from lxml.etree import ElementTree
7+
from xmldiff.actions import (
8+
DeleteAttrib,
9+
DeleteNamespace,
10+
DeleteNode,
11+
InsertAttrib,
12+
InsertComment,
13+
InsertNamespace,
14+
InsertNode,
15+
MoveNode,
16+
RenameAttrib,
17+
RenameNode,
18+
UpdateAttrib,
19+
UpdateTextAfter,
20+
UpdateTextIn,
21+
)
22+
from xmldiff.formatting import BaseFormatter
23+
24+
__version__: str
25+
FORMATTERS: Mapping[str, BaseFormatter]
26+
27+
_ACTIONS: TypeAlias = (
28+
DeleteNode
29+
| InsertNode
30+
| RenameNode
31+
| MoveNode
32+
| UpdateTextIn
33+
| UpdateTextAfter
34+
| UpdateAttrib
35+
| DeleteAttrib
36+
| InsertAttrib
37+
| RenameAttrib
38+
| InsertComment
39+
| InsertNamespace
40+
| DeleteNamespace
41+
)
42+
43+
@overload
44+
def diff_trees(
45+
left: ElementTree, right: ElementTree, diff_options: dict[str, Any] | None = None, formatter: None = None
46+
) -> Iterable[_ACTIONS]: ...
47+
@overload
48+
def diff_trees(
49+
left: ElementTree, right: ElementTree, *, diff_options: dict[str, Any] | None = None, formatter: BaseFormatter = ...
50+
) -> str: ...
51+
@overload
52+
def diff_texts(
53+
left: str, right: str, diff_options: dict[str, Any] | None = None, formatter: None = None
54+
) -> Iterable[_ACTIONS]: ...
55+
@overload
56+
def diff_texts(left: str, right: str, *, diff_options: dict[str, Any] | None = None, formatter: BaseFormatter = ...) -> str: ...
57+
@overload
58+
def diff_files(
59+
left: str, right: str, diff_options: dict[str, Any] | None = None, formatter: None = None
60+
) -> Iterable[_ACTIONS]: ...
61+
@overload
62+
def diff_files(left: str, right: str, *, diff_options: dict[str, Any] | None = None, formatter: BaseFormatter = ...) -> str: ...
63+
def validate_F(arg: float | str) -> float: ...
64+
def make_diff_parser() -> ArgumentParser: ...
65+
def diff_command(args: Sequence[str] | None = None) -> int | None: ...
66+
def patch_tree(actions, tree): ...
67+
def patch_text(actions, tree): ...
68+
def patch_file(actions, tree, diff_encoding=None): ...
69+
def make_patch_parser(): ...
70+
def patch_command(args=None) -> None: ...

stubs/xmldiff/xmldiff/patch.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Generator
3+
4+
class Patcher:
5+
@property
6+
def nsmap(self): ...
7+
def patch(self, actions, tree): ...
8+
def handle_action(self, action, tree) -> None: ...
9+
10+
class DiffParser:
11+
def parse(self, diff) -> Generator[Incomplete]: ...
12+
def make_action(self, line): ...

stubs/xmldiff/xmldiff/utils.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Generator
3+
from re import Pattern
4+
5+
RESERVED_NS: Pattern[str]
6+
7+
def post_order_traverse(node) -> Generator[Incomplete, Incomplete]: ...
8+
def reverse_post_order_traverse(node) -> Generator[Incomplete, Incomplete]: ...
9+
def breadth_first_traverse(node) -> Generator[Incomplete]: ...
10+
def longest_common_subsequence(left_sequence, right_sequence, eqfn=...): ...
11+
12+
WHITESPACE: Incomplete
13+
14+
def cleanup_whitespace(text): ...
15+
def getpath(element, tree=None): ...
16+
def make_ascii_tree(element): ...

0 commit comments

Comments
 (0)