Skip to content

Typing issue when updating from 3.9.1, suggested documentation update #2949

@thomas-forte

Description

@thomas-forte

Explanation

While updating my app, something changed causing an error within pypdf. The issue was due to the dictionary of fields I was sending into update_page_form_field_values, that was previously a mix of strings, integers, and float values. I discovered the note in the doc-string that the function expected a string, list of strings or a tuple.

Correcting this fixed my issue, but it took some time to find as the error was nested, and that the typing on fields is Any, especially since floats worked previously.

Updating the typing from Any to the expected types could be helpful to anyone else with this problem. Or another suggestion would be to coerce to a string type on TextStringObject simply by calling str() on the value

Either way my issue is fixed, I love this package!

Code Example

def update_page_form_field_values(

def update_page_form_field_values(
        self,
        page: Union[PageObject, List[PageObject], None],
        fields: Dict[str, Union[str, List[str], Tuple[str, str, float]]],
        flags: FA.FfBits = FFBITS_NUL,
        auto_regenerate: Optional[bool] = True,
    ) -> None:

OR

class TextStringObject(str, PdfObject): # noqa: SLOT000

def __new__(cls, value: Any) -> "TextStringObject":
    value=str(value)
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions