Skip to content

Some Widget properties do not have the correct type #4873

@MisterStump

Description

@MisterStump

Description of the bug

VS Code is displaying this error for at least 2 of the Widget properties, "field_name" and "rect".

Cannot assign to attribute "field_name" for class "Widget"
  Expression of type "Literal['Custom Name for Field']" cannot be assigned to attribute "field_name" of class "Widget"
    "Literal['Custom Name for Field']" is not assignable to "None"

The code still runs fine and both properties work. They are just showing red underlines in my IDE because they are only expecting "None" type. I am not experiencing the issue with any other properties or libraries I'm using currently.

How to reproduce the bug

This simple script shows the error. "field_name" and "rect" are both underlined, but "field_type" is not.

import pymupdf

#Create a new PDF
doc = pymupdf.open()
page = doc.new_page()

#Define a widget
wgt = pymupdf.Widget()
wgt.field_name = "Custom Name for Field"
wgt.rect = pymupdf.Rect(20, 10, 2200, 30)
wgt.field_type = 7

#Add widget
page.add_widget(wgt)

#Save pdf
doc.save("problem_example.pdf")
doc.close()

This code does work just fine, including the underlined fields. I think it is just an incorrect type hint.

PyMuPDF version

1.26.7

Operating system

Windows

Python version

3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions