Skip to content

Commit 9647ce6

Browse files
committed
Tidy up
1 parent caa393e commit 9647ce6

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

spacy_layout/layout.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,14 @@ def _texts_to_doc(
150150
def _get_span_layout(
151151
self, item: DoclingItem, pages: dict[int, PageLayout]
152152
) -> SpanLayout | None:
153-
bounding_box = None
154153
if item.prov:
155154
prov = item.prov[0]
156155
page = pages[prov.page_no]
157156
if page.width and page.height:
158157
x, y, width, height = get_bounding_box(prov.bbox, page.height)
159-
bounding_box = SpanLayout(
158+
return SpanLayout(
160159
x=x, y=y, width=width, height=height, page_no=prov.page_no
161160
)
162-
return bounding_box
163161

164162
def get_pages(self, doc: Doc) -> list[tuple[PageLayout, list[Span]]]:
165163
"""Get all pages and their layout spans."""

spacy_layout/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import TYPE_CHECKING, Callable
2+
from typing import TYPE_CHECKING, Any, Callable
33

44
from docling_core.types.doc.base import CoordOrigin
55
from pandas import DataFrame
@@ -13,7 +13,7 @@
1313
OBJ_TYPES = {"SpanLayout": SpanLayout, "DocLayout": DocLayout, "PageLayout": PageLayout}
1414

1515

16-
def encode_obj(obj, chain: Callable | None = None):
16+
def encode_obj(obj: Any, chain: Callable | None = None) -> Any:
1717
"""Convert custom dataclass to dict for serialization."""
1818
if isinstance(obj, tuple(OBJ_TYPES.values())):
1919
result = dataclasses.asdict(obj)
@@ -22,22 +22,22 @@ def encode_obj(obj, chain: Callable | None = None):
2222
return obj if chain is None else chain(obj)
2323

2424

25-
def decode_obj(obj, chain: Callable | None = None):
25+
def decode_obj(obj: Any, chain: Callable | None = None) -> Any:
2626
"""Load custom dataclass from serialized dict."""
2727
if isinstance(obj, dict) and obj.get(TYPE_ATTR) in OBJ_TYPES:
2828
obj_type = obj.pop(TYPE_ATTR)
2929
return OBJ_TYPES[obj_type].from_dict(obj)
3030
return obj if chain is None else chain(obj)
3131

3232

33-
def encode_df(obj, chain: Callable | None = None):
33+
def encode_df(obj: Any, chain: Callable | None = None) -> Any:
3434
"""Convert pandas.DataFrame for serialization."""
3535
if isinstance(obj, DataFrame):
3636
return {"data": obj.to_dict(), TYPE_ATTR: "DataFrame"}
3737
return obj if chain is None else chain(obj)
3838

3939

40-
def decode_df(obj, chain: Callable | None = None):
40+
def decode_df(obj: Any, chain: Callable | None = None) -> Any:
4141
"""Load pandas.DataFrame from serialized data."""
4242
if isinstance(obj, dict) and obj.get(TYPE_ATTR) == "DataFrame":
4343
return DataFrame(obj["data"])

0 commit comments

Comments
 (0)