Skip to content

Commit 32ed4eb

Browse files
committed
Remove ID type alias
1 parent 6b842fa commit 32ed4eb

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

pygexml/page.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,9 @@ def __str__(self) -> str:
8383
return " ".join(str(p) for p in self.polygon.points)
8484

8585

86-
type ID = str
87-
88-
8986
@dataclass
9087
class TextLine(DataClassJsonMixin):
91-
id: ID
88+
id: str
9289
coords: Coords
9390
text: str
9491

@@ -155,9 +152,9 @@ def words(self) -> Iterable[str]:
155152

156153
@dataclass
157154
class TextRegion(DataClassJsonMixin):
158-
id: ID
155+
id: str
159156
coords: Coords
160-
textlines: dict[ID, TextLine]
157+
textlines: dict[str, TextLine]
161158

162159
@classmethod
163160
def from_xml(cls, element: Element) -> "TextRegion":
@@ -200,7 +197,7 @@ def from_alto(cls, element: Element) -> "TextRegion":
200197
)
201198
)
202199

203-
textlines: dict[ID, TextLine] = {}
200+
textlines: dict[str, TextLine] = {}
204201
for child in element:
205202
if QName(child).localname == "TextLine":
206203
tl = TextLine.from_alto(child)
@@ -213,7 +210,7 @@ def from_alto(cls, element: Element) -> "TextRegion":
213210
id=str(element.attrib["ID"]), coords=coords, textlines=textlines
214211
)
215212

216-
def lookup_textline(self, id: ID) -> TextLine | None:
213+
def lookup_textline(self, id: str) -> TextLine | None:
217214
return self.textlines.get(id)
218215

219216
def all_text(self) -> Iterable[str]:
@@ -226,7 +223,7 @@ def all_words(self) -> Iterable[str]:
226223
@dataclass
227224
class Page(DataClassJsonMixin):
228225
image_filename: str
229-
regions: dict[ID, TextRegion]
226+
regions: dict[str, TextRegion]
230227

231228
@classmethod
232229
def from_xml(cls, element: Element) -> "Page":
@@ -307,7 +304,7 @@ def from_alto_file(cls, file: Path | str, encoding: str = "utf-8") -> "Page":
307304
xml_string = path.read_text(encoding=encoding)
308305
return Page.from_alto_string(xml_string)
309306

310-
def lookup_region(self, id: ID) -> TextRegion | None:
307+
def lookup_region(self, id: str) -> TextRegion | None:
311308
return self.regions.get(id)
312309

313310
def all_text(self) -> Iterable[str]:

test/test_page.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pygexml.strategies import *
1010
from pygexml.geometry import Point, Box, Polygon
11-
from pygexml.page import Coords, ID, TextLine, TextRegion, Page
11+
from pygexml.page import Coords, TextLine, TextRegion, Page
1212

1313
############## Tests for Coords ####################
1414

@@ -333,7 +333,7 @@ def test_textregion_line_lookup(line: TextLine, region: TextRegion) -> None:
333333

334334

335335
@given(st.text(), st_text_regions)
336-
def test_textregion_line_lookup_not_found(id: ID, region: TextRegion) -> None:
336+
def test_textregion_line_lookup_not_found(id: str, region: TextRegion) -> None:
337337
assume(not id in region.textlines)
338338
assert region.lookup_textline(id) is None
339339

0 commit comments

Comments
 (0)