Skip to content

Fix typing in get_possible_radios #120

@nonprofittechy

Description

@nonprofittechy

Run python -m mypy .
formfyxer/pdf_wrangling.py:1110: error: Item "str" of "Union[str, BinaryIO, Mat]" has no attribute "shape" [union-attr]
formfyxer/pdf_wrangling.py:1110: error: Item "BinaryIO" of "Union[str, BinaryIO, Mat]" has no attribute "shape" [union-attr]
formfyxer/pdf_wrangling.py:1158: error: Item "str" of "Union[str, BinaryIO, Mat]" has no attribute "shape" [union-attr]
formfyxer/pdf_wrangling.py:1158: error: Item "BinaryIO" of "Union[str, BinaryIO, Mat]" has no attribute "shape" [union-attr]
formfyxer/tests/test_lit_explorer.py:47: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]

looks like the problem is that we re-use the variable img -- starts as a string and gets turned into a cv2 object. so typing is messed up.

def get_possible_radios(img: Union[str, BinaryIO, cv2.Mat]):
    """Even though it's called "radios", it just gets things shaped like circles, not
    doing any semantic analysis yet."""
    if isinstance(img, str):
        # 0 is for the flags: means nothing special is being used
        img = cv2.imread(img, 0)
    if isinstance(img, BinaryIO):
        img = cv2.imdecode(np.frombuffer(img.read(), np.uint8), 0)

    rows = img.shape[0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtyping

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions