Skip to content

Commit 3f5d1da

Browse files
committed
fix: resolve remaining pyupgrade lint errors
- Import Callable from collections.abc instead of typing (UP035) - Replace Union[X, Y] with X | Y for type annotations (UP007) - Remove unused Union import from typing - Apply ruff formatting This resolves the remaining UP lint errors in code-checks / lint (3.12) Signed-off-by: Br1an67 <932039080@qq.com>
1 parent b9ae4fb commit 3f5d1da

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

docling/backend/msword_backend.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import logging
22
import re
3+
from collections.abc import Callable
34
from copy import deepcopy
45
from io import BytesIO
56
from pathlib import Path
6-
from typing import Any, Callable, Final, Union
7+
from typing import Any, Final
78
from urllib.parse import urlparse
89

910
from docling_core.types.doc import (
@@ -65,9 +66,7 @@ class MsWordDocumentBackend(DeclarativeDocumentBackend):
6566
}
6667

6768
@override
68-
def __init__(
69-
self, in_doc: "InputDocument", path_or_stream: Union[BytesIO, Path]
70-
) -> None:
69+
def __init__(self, in_doc: "InputDocument", path_or_stream: BytesIO | Path) -> None:
7170
super().__init__(in_doc, path_or_stream)
7271
self.XML_KEY = f"{self._W_NS_CLARK}val"
7372
self.xml_namespaces = {
@@ -78,7 +77,7 @@ def __init__(
7877
)
7978
# self.initialise(path_or_stream)
8079
# Word file:
81-
self.path_or_stream: Union[BytesIO, Path] = path_or_stream
80+
self.path_or_stream: BytesIO | Path = path_or_stream
8281
self.valid: bool = False
8382
# Initialise the parents for the hierarchy
8483
self.max_levels: int = 10
@@ -178,7 +177,7 @@ def convert(self) -> DoclingDocument:
178177

179178
@staticmethod
180179
def load_msword_file(
181-
path_or_stream: Union[BytesIO, Path], document_hash: str
180+
path_or_stream: BytesIO | Path, document_hash: str
182181
) -> DocxDocument:
183182
try:
184183
if isinstance(path_or_stream, BytesIO):
@@ -681,7 +680,7 @@ def _get_paragraph_elements(self, paragraph: Paragraph):
681680
return [("", None, None)]
682681

683682
paragraph_elements: list[
684-
tuple[str, Formatting | None, Union[AnyUrl, Path] | None]
683+
tuple[str, Formatting | None, AnyUrl | Path | None]
685684
] = []
686685
group_text = ""
687686
previous_format = None

0 commit comments

Comments
 (0)