Skip to content

Deserialization of TextRegion and Page throws TypeError #8

@memowe

Description

@memowe

This problem was reported by @devolt5. It seems to be dataclasses_json-related:

File "env/lib/python3.12/site-packages/dataclasses_json/core.py", line 318, in _decode_generic
    res = collection_type(xs)
          ^^^^^^^^^^^^^^^^^^^
TypeError: 'typing.TypeAliasType' object is not callable

These tests should demonstrate the problem:

# TextLine: works
def test_textline_serialization_roundtrip() -> None:
    tl = TextLine(id="tl-id", coords=Coords.parse("1,2 3,4"), text="foo bar")
    assert TextLine.from_dict(tl.to_dict()) == tl

# TextRegion: fails
def test_textregion_serialization_roundtrip() -> None:
    tr = TextRegion(
        id="tr-id",
        coords=Coords.parse("1,2 3,4"),
        textlines={
            "tl-1": TextLine(id="tl-1", coords=Coords.parse("1,2 3,4"), text="foo")
        },
    )
    assert TextRegion.from_dict(tr.to_dict()) == tr

# TextRegion: fails
def test_page_serialization_roundtrip() -> None:
    pa = Page(
        image_filename="a.jpg",
        regions={
            "tr-1": TextRegion(
                id="tr-1",
                coords=Coords.parse("1,2 3,4"),
                textlines={
                    "tl-1": TextLine(
                        id="tl-1", coords=Coords.parse("1,2 3,4"), text="foo"
                    )
                },
            )
        },
    )
    assert Page.from_dict(pa.to_dict()) == pa

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions