Skip to content

extract_links regularly zip()s with mismatching sizes (when concatenating files) #3667

@RemyKap

Description

@RemyKap

The below code includes the very confusing warning that "Annotation sizes differ: {old_annotations} vs. {new_annotations}". Not only is this borderline unintelligible to people not intimately familiar with the project, it is also a warning, causing excessive prints to console.

As far as I can tell from the information that is possible to glean from a quick look over the source code, this should be a debug statement. In addition, it would also be beneficial to include some sort of signature, because in larger projects finding what exactly caused an error is difficult (I had to resort to searching the source of all my installed packages).

Finally, the docstrings seem to imply this might also be a bug. The caller (_add_page() of the function in question (extract_links()) states that simply

the page may contain links to other pages, and those other
pages may or may not already be added. we store the
information we need, so that we can resolve the references
later.

While the function in question seems to assume that the pages are the same for some reason.

Extracts links from two pages on the assumption that the two pages are
the same. Produces one list of (new link, old link) tuples.

new_annotations = new_page.get("/Annots", ArrayObject()).get_object()
old_annotations = old_page.get("/Annots", ArrayObject()).get_object()
if is_null_or_none(new_annotations):
new_annotations = ArrayObject()
if is_null_or_none(old_annotations):
old_annotations = ArrayObject()
if not isinstance(new_annotations, ArrayObject) or not isinstance(old_annotations, ArrayObject):
logger_warning(
f"Expected annotation arrays: {old_annotations} {new_annotations}. Ignoring annotations.",
__name__
)
return []
if len(new_annotations) != len(old_annotations):
logger_warning(f"Annotation sizes differ: {old_annotations} vs. {new_annotations}", __name__)
new_links = [_build_link(link, new_page) for link in new_annotations]
old_links = [_build_link(link, old_page) for link in old_annotations]

Metadata

Metadata

Assignees

No one assigned

    Labels

    workflow-bookmarksFrom a users perspective, bookmarks is the affected feature/workflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions