Skip to content

Add basic type annotations #71

@hflamme

Description

@hflamme

Problem

After updating the version, the interface of some function has changed. My static type checker did not pick it up resulting in unexpected failures.

Solution suggestion

Adding some basic type annotations would have caught this issue upfront.

Example:

from io import BytesIO
from typing import Literal

def get_xml_from_pdf(
    pdf_file: str | bytes | BytesIO, 
    check_xsd: bool = True, 
    check_schematron: bool = True, 
    filenames: list[str] = []
) -> tuple[str | Literal[False], bytes | Literal[False]]:
    ...

or compatible with python 3.7+

from io import BytesIO
from typing import List, Tuple, Union
from typing_extensions import Literal  # for Python 3.7

def get_xml_from_pdf(
    pdf_file: Union[str, bytes, BytesIO],
    check_xsd: bool = True,
    check_schematron: bool = True,
    filenames: List[str] = None,
) -> Tuple[Union[str, Literal[False]], Union[bytes, Literal[False]]]:
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions