diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 2b724712154b..084dc2c81add 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -99,7 +99,6 @@ "stubs/tqdm", "stubs/vobject", "stubs/workalendar", - "stubs/xmldiff", ], "typeCheckingMode": "strict", // TODO: Complete incomplete stubs diff --git a/stubs/xmldiff/xmldiff/actions.pyi b/stubs/xmldiff/xmldiff/actions.pyi index bbdc75a0dd92..565b222eba0d 100644 --- a/stubs/xmldiff/xmldiff/actions.pyi +++ b/stubs/xmldiff/xmldiff/actions.pyi @@ -1,37 +1,36 @@ -from _typeshed import Incomplete -from typing import NamedTuple +from typing import NamedTuple, TypeAlias class DeleteNode(NamedTuple): node: str class InsertNode(NamedTuple): - target: Incomplete + target: str tag: str position: int class RenameNode(NamedTuple): node: str - tag: Incomplete + tag: str class MoveNode(NamedTuple): node: str - target: Incomplete + target: str position: int class UpdateTextIn(NamedTuple): node: str - text: Incomplete - oldtext: Incomplete | None = None + text: str | None + oldtext: str | None = None class UpdateTextAfter(NamedTuple): node: str - text: Incomplete - oldtext: Incomplete | None = None + text: str | None + oldtext: str | None = None class UpdateAttrib(NamedTuple): node: str name: str - value: Incomplete + value: str class DeleteAttrib(NamedTuple): node: str @@ -40,7 +39,7 @@ class DeleteAttrib(NamedTuple): class InsertAttrib(NamedTuple): node: str name: str - value: Incomplete + value: str class RenameAttrib(NamedTuple): node: str @@ -48,13 +47,29 @@ class RenameAttrib(NamedTuple): newname: str class InsertComment(NamedTuple): - target: Incomplete - position: Incomplete - text: Incomplete + target: str + position: int + text: str | None class InsertNamespace(NamedTuple): - prefix: str + prefix: str | None uri: str class DeleteNamespace(NamedTuple): - prefix: str + prefix: str | None + +_Action: TypeAlias = ( # noqa: Y047 # Used in other modules + DeleteNode + | InsertNode + | RenameNode + | MoveNode + | UpdateTextIn + | UpdateTextAfter + | UpdateAttrib + | DeleteAttrib + | InsertAttrib + | RenameAttrib + | InsertComment + | InsertNamespace + | DeleteNamespace +) diff --git a/stubs/xmldiff/xmldiff/diff.pyi b/stubs/xmldiff/xmldiff/diff.pyi index 3dff61747a35..95f9e741634f 100644 --- a/stubs/xmldiff/xmldiff/diff.pyi +++ b/stubs/xmldiff/xmldiff/diff.pyi @@ -1,36 +1,46 @@ -from _typeshed import Incomplete -from collections.abc import Generator -from typing import Literal +from collections.abc import Generator, Iterable, Sequence +from typing import Any, Literal, TypeAlias + +from xmldiff import actions + +_Element: TypeAlias = Any # lxml.etree._Element +_ElementTree: TypeAlias = Any # lxml.etree._ElementTree class Differ: F: float - uniqueattrs: Incomplete - fast_match: Incomplete - best_match: Incomplete - ignored_attrs: Incomplete + uniqueattrs: Iterable[str | Sequence[str]] + fast_match: bool + best_match: bool + ignored_attrs: Iterable[str] def __init__( self, F: float | None = None, - uniqueattrs=None, + uniqueattrs: Iterable[str | Sequence[str]] | None = None, ratio_mode: Literal["accurate", "fast", "faster"] = "fast", fast_match: bool = False, best_match: bool = False, - ignored_attrs=[], + ignored_attrs: Iterable[str] = [], ) -> None: ... - left: Incomplete - right: Incomplete + left: _Element | None + right: _Element | None 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]: ... + def set_trees(self, left: _Element | _ElementTree, right: _Element | _ElementTree) -> None: ... + def append_match(self, lnode: _Element, rnode: _Element, max_match: float | None) -> None: ... + def match( + self, left: _Element | _ElementTree | None = None, right: _Element | _ElementTree | None = None + ) -> list[tuple[_Element, _Element, float | None]]: ... + def node_ratio(self, left: _Element, right: _Element) -> float: ... + def node_text(self, node: _Element) -> str: ... + def node_attribs(self, node: _Element) -> dict[str, str]: ... + def leaf_ratio(self, left: _Element, right: _Element) -> float: ... + def child_ratio(self, left: _Element, right: _Element) -> float | None: ... + def update_node_tag(self, left: _Element, right: _Element) -> Generator[actions.RenameNode]: ... + def update_node_attr( + self, left: _Element, right: _Element + ) -> Generator[actions.UpdateAttrib | actions.RenameAttrib | actions.InsertAttrib | actions.DeleteAttrib]: ... + def update_node_text(self, left: _Element, right: _Element) -> Generator[actions.UpdateTextIn | actions.UpdateTextAfter]: ... + def find_pos(self, node: _Element) -> int: ... + def align_children(self, left: _Element, right: _Element) -> Generator[actions.MoveNode]: ... + def diff( + self, left: _Element | _ElementTree | None = None, right: _Element | _ElementTree | None = None + ) -> Generator[actions._Action]: ... diff --git a/stubs/xmldiff/xmldiff/diff_match_patch.pyi b/stubs/xmldiff/xmldiff/diff_match_patch.pyi index 476b35acc453..9c4932be73bf 100644 --- a/stubs/xmldiff/xmldiff/diff_match_patch.pyi +++ b/stubs/xmldiff/xmldiff/diff_match_patch.pyi @@ -1,4 +1,8 @@ -from _typeshed import Incomplete +from collections.abc import Iterable, Sequence +from re import Pattern +from typing import TypeAlias, overload + +_Diff: TypeAlias = tuple[int, str] class diff_match_patch: Diff_Timeout: float @@ -13,46 +17,55 @@ class diff_match_patch: 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): ... + def diff_main(self, text1: str, text2: str, checklines: bool = True, deadline: float | None = None) -> list[_Diff]: ... + def diff_compute(self, text1: str, text2: str, checklines: bool, deadline: float) -> list[_Diff]: ... + def diff_lineMode(self, text1: str, text2: str, deadline: float) -> list[_Diff]: ... + def diff_bisect(self, text1: str, text2: str, deadline: float) -> list[_Diff]: ... + def diff_bisectSplit(self, text1: str, text2: str, x: int, y: int, deadline: float) -> list[_Diff]: ... + def diff_linesToChars(self, text1: str, text2: str) -> tuple[str, str, list[str]]: ... + def diff_charsToLines(self, diffs: list[_Diff], lineArray: Sequence[str]) -> None: ... + def diff_commonPrefix(self, text1: str, text2: str) -> int: ... + def diff_commonSuffix(self, text1: str, text2: str) -> int: ... + def diff_commonOverlap(self, text1: str, text2: str) -> int: ... + def diff_halfMatch(self, text1: str, text2: str) -> tuple[str, str, str, str, str] | None: ... + def diff_cleanupSemantic(self, diffs: list[_Diff]) -> None: ... + def diff_cleanupSemanticLossless(self, diffs: list[_Diff]) -> None: ... + BLANKLINEEND: Pattern[str] + BLANKLINESTART: Pattern[str] + def diff_cleanupEfficiency(self, diffs: list[_Diff]) -> None: ... + def diff_cleanupMerge(self, diffs: list[_Diff]) -> None: ... + def diff_xIndex(self, diffs: Sequence[_Diff], loc: int) -> int: ... + def diff_prettyHtml(self, diffs: Sequence[_Diff]) -> str: ... + def diff_text1(self, diffs: Sequence[_Diff]) -> str: ... + def diff_text2(self, diffs: Sequence[_Diff]) -> str: ... + def diff_levenshtein(self, diffs: Sequence[_Diff]) -> int: ... + def diff_toDelta(self, diffs: Sequence[_Diff]) -> str: ... + def diff_fromDelta(self, text1: str, delta: str) -> list[_Diff]: ... + def match_main(self, text: str, pattern: str, loc: int) -> int: ... + def match_bitap(self, text: str, pattern: str, loc: int) -> int: ... + def match_alphabet(self, pattern: str) -> dict[str, int]: ... + def patch_addContext(self, patch: patch_obj, text: str) -> None: ... + + @overload + def patch_make(self, a: str, b: str, c: None = None) -> list[patch_obj]: ... + @overload + def patch_make(self, a: list[_Diff], b: None = None, c: None = None) -> list[patch_obj]: ... + @overload + def patch_make(self, a: str, b: list[_Diff], c: None = None) -> list[patch_obj]: ... + @overload + def patch_make(self, a: str, b: str, c: list[_Diff]) -> list[patch_obj]: ... + + def patch_deepCopy(self, patches: Iterable[patch_obj]) -> list[patch_obj]: ... + def patch_apply(self, patches: Iterable[patch_obj], text: str) -> tuple[str, list[bool]]: ... + def patch_addPadding(self, patches: Sequence[patch_obj]) -> str: ... + def patch_splitMax(self, patches: list[patch_obj]) -> None: ... + def patch_toText(self, patches: Iterable[patch_obj]) -> str: ... + def patch_fromText(self, textline: str) -> list[patch_obj]: ... class patch_obj: - diffs: Incomplete - start1: Incomplete - start2: Incomplete + diffs: list[_Diff] + start1: int | None + start2: int | None length1: int length2: int def __init__(self) -> None: ... diff --git a/stubs/xmldiff/xmldiff/formatting.pyi b/stubs/xmldiff/xmldiff/formatting.pyi index 02399462274d..30dd38e4583e 100644 --- a/stubs/xmldiff/xmldiff/formatting.pyi +++ b/stubs/xmldiff/xmldiff/formatting.pyi @@ -1,13 +1,17 @@ -from _typeshed import Incomplete -from collections.abc import Generator -from typing import Final, NamedTuple +from collections.abc import Generator, Iterable, Mapping +from typing import Any, Final, NamedTuple, TypeAlias + +from xmldiff.actions import _Action +from xmldiff.diff import Differ + +_Element: TypeAlias = Any # lxml.etree._Element DIFF_NS: Final[str] DIFF_PREFIX: Final[str] -INSERT_NAME: Final[Incomplete] -DELETE_NAME: Final[Incomplete] -REPLACE_NAME: Final[Incomplete] -RENAME_NAME: Final[Incomplete] +INSERT_NAME: Final[str] +DELETE_NAME: Final[str] +REPLACE_NAME: Final[str] +RENAME_NAME: Final[str] WS_BOTH: Final[int] WS_TEXT: Final[int] WS_TAGS: Final[int] @@ -18,63 +22,68 @@ 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: ... + def __init__(self, normalize: int = 1, pretty_print: bool = False) -> None: ... + def prepare(self, left_tree: _Element, right_tree: _Element) -> None: ... + def format(self, diff: Iterable[_Action], orig_tree: _Element) -> str: ... class PlaceholderEntry(NamedTuple): - element: Incomplete - ttype: Incomplete - close_ph: Incomplete + element: _Element + ttype: int + close_ph: str | None 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): ... + text_tags: Iterable[str] + formatting_tags: Iterable[str] + placeholder2tag: dict[str, PlaceholderEntry] + tag2placeholder: dict[tuple[str, int, str | None], str] + placeholder: int + diff_tags: dict[str, tuple[str, str]] + def __init__(self, text_tags: Iterable[str] = (), formatting_tags: Iterable[str] = ()) -> None: ... + def get_placeholder(self, element: _Element, ttype: int, close_ph: str | None) -> str: ... + def is_placeholder(self, char: str) -> bool: ... + def is_formatting(self, element: _Element) -> bool: ... + def do_element(self, element: _Element) -> None: ... + def do_tree(self, tree: _Element) -> None: ... + def split_string(self, text: str) -> list[str]: ... + def undo_string(self, text: str) -> _Element: ... + def undo_element(self, elem: _Element) -> None: ... + def undo_tree(self, tree: _Element) -> None: ... + def mark_diff(self, ph: str, action: str, attributes: Mapping[str, str] | None = None) -> str: ... + def wrap_diff(self, text: str, action: str, attributes: Mapping[str, str] | None = None) -> str: ... class XMLFormatter(BaseFormatter): - normalize: Incomplete - pretty_print: Incomplete - text_tags: Incomplete - formatting_tags: Incomplete - use_replace: Incomplete - placeholderer: Incomplete + normalize: int + pretty_print: bool + text_tags: Iterable[str] + formatting_tags: Iterable[str] + use_replace: bool + placeholderer: PlaceholderMaker def __init__( - self, normalize=0, pretty_print: bool = True, text_tags=(), formatting_tags=(), use_replace: bool = False + self, + normalize: int = 0, + pretty_print: bool = True, + text_tags: Iterable[str] = (), + formatting_tags: Iterable[str] = (), + 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: ... + def prepare(self, left_tree: _Element, right_tree: _Element) -> None: ... + def finalize(self, result_tree: _Element) -> None: ... + def format(self, diff: Iterable[_Action], orig_tree: _Element, differ: Differ | None = None) -> str: ... + def render(self, result: _Element) -> str: ... + def handle_action(self, action: _Action, result: _Element) -> 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): ... + normalize: int + def __init__(self, normalize: int = 1, pretty_print: bool = False) -> None: ... + def prepare(self, left: _Element, right: _Element) -> None: ... + def finalize(self, left: _Element, right: _Element) -> None: ... + def format(self, diff: Iterable[_Action], orig_tree: _Element) -> str: ... + def handle_action(self, action: _Action) -> str: ... 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]: ... + normalize: int + def __init__(self, normalize: int = 1, pretty_print: bool = False) -> None: ... + def prepare(self, left: _Element, right: _Element) -> None: ... + def finalize(self, left: _Element, right: _Element) -> None: ... + def format(self, diff: Iterable[_Action], orig_tree: _Element) -> str: ... + def handle_action(self, action: _Action, orig_tree: _Element) -> Generator[tuple[str, ...]]: ... diff --git a/stubs/xmldiff/xmldiff/main.pyi b/stubs/xmldiff/xmldiff/main.pyi index 8283095ec0bd..c100fd931255 100644 --- a/stubs/xmldiff/xmldiff/main.pyi +++ b/stubs/xmldiff/xmldiff/main.pyi @@ -1,42 +1,15 @@ +from _typeshed import StrOrBytesPath, SupportsRead from argparse import ArgumentParser from collections.abc import Iterable, Mapping, Sequence from typing import Any, TypeAlias, overload -from xmldiff.actions import ( - DeleteAttrib, - DeleteNamespace, - DeleteNode, - InsertAttrib, - InsertComment, - InsertNamespace, - InsertNode, - MoveNode, - RenameAttrib, - RenameNode, - UpdateAttrib, - UpdateTextAfter, - UpdateTextIn, -) +from xmldiff.actions import _Action 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 -) +_ACTIONS: TypeAlias = _Action _ET: TypeAlias = Any # lxml.etree._ElementTree @overload @@ -65,8 +38,10 @@ def diff_files( 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: ... +def patch_tree(actions: Iterable[_ACTIONS], tree: _ET) -> _ET: ... +def patch_text(actions: str, tree: str | bytes) -> str: ... +def patch_file( + actions: str | SupportsRead[str], tree: StrOrBytesPath | SupportsRead[bytes | str], diff_encoding: str | None = None +) -> str: ... +def make_patch_parser() -> ArgumentParser: ... +def patch_command(args: Sequence[str] | None = None) -> None: ... diff --git a/stubs/xmldiff/xmldiff/patch.pyi b/stubs/xmldiff/xmldiff/patch.pyi index ddcc62436ca5..560bdd6b298e 100644 --- a/stubs/xmldiff/xmldiff/patch.pyi +++ b/stubs/xmldiff/xmldiff/patch.pyi @@ -1,16 +1,20 @@ -from _typeshed import Incomplete -from collections.abc import Generator +from collections.abc import Generator, Iterable from re import Pattern -from typing import Final +from typing import Any, Final, TypeAlias + +from xmldiff.actions import _Action + +_Element: TypeAlias = Any # lxml.etree._Element +_ElementTree: TypeAlias = Any # lxml.etree._ElementTree DIFF_SPLIT: Final[Pattern[str]] class Patcher: @property - def nsmap(self): ... - def patch(self, actions, tree): ... - def handle_action(self, action, tree) -> None: ... + def nsmap(self) -> dict[str | None, str]: ... + def patch(self, actions: Iterable[_Action], tree: _Element | _ElementTree) -> _Element: ... + def handle_action(self, action: _Action, tree: _Element) -> None: ... class DiffParser: - def parse(self, diff) -> Generator[Incomplete]: ... - def make_action(self, line): ... + def parse(self, diff: str) -> Generator[_Action]: ... + def make_action(self, line: str) -> _Action: ... diff --git a/stubs/xmldiff/xmldiff/utils.pyi b/stubs/xmldiff/xmldiff/utils.pyi index 264fb6023e25..855d68de93fe 100644 --- a/stubs/xmldiff/xmldiff/utils.pyi +++ b/stubs/xmldiff/xmldiff/utils.pyi @@ -1,16 +1,23 @@ -from _typeshed import Incomplete -from collections.abc import Generator +from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern +from typing import Any, TypeAlias, TypeVar + +_Element: TypeAlias = Any # lxml.etree._Element +_ElementTree: TypeAlias = Any # lxml.etree._ElementTree +_T1 = TypeVar("_T1") +_T2 = TypeVar("_T2") 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=...): ... +def post_order_traverse(node: _Element) -> Generator[_Element]: ... +def reverse_post_order_traverse(node: _Element) -> Generator[_Element]: ... +def breadth_first_traverse(node: _Element) -> Generator[_Element]: ... +def longest_common_subsequence( + left_sequence: Sequence[_T1], right_sequence: Sequence[_T2], eqfn: Callable[[_T1, _T2], bool] = ... +) -> Iterable[tuple[int, int]]: ... -WHITESPACE: Incomplete +WHITESPACE: Pattern[str] -def cleanup_whitespace(text): ... -def getpath(element, tree=None): ... -def make_ascii_tree(element): ... +def cleanup_whitespace(text: str) -> str: ... +def getpath(element: _Element, tree: _ElementTree | None = None) -> str: ... +def make_ascii_tree(element: _Element) -> str: ...