Skip to content

PPF-1707: Add a __repr__ method to the Widget base class#1712

Open
annaswims wants to merge 1 commit intochinapandaman:masterfrom
annaswims:widget_info
Open

PPF-1707: Add a __repr__ method to the Widget base class#1712
annaswims wants to merge 1 commit intochinapandaman:masterfrom
annaswims:widget_info

Conversation

@annaswims
Copy link
Copy Markdown
Contributor

@annaswims annaswims commented Apr 14, 2026

All Submissions:

  • Have you followed the guidelines in the developer guide?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you lint your code locally prior to submission?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

What this PR does

#1711
Adds __repr__ to the Widget base class (middleware/base.py) so that widgets render meaningfully when inspected. The output includes the class name, name, value, and all non-None public attributes, while omitting internal bookkeeping fields (SET_ATTR_TRIGGER_HOOK_MAP, attr_set_tracker, hooks_to_trigger) and _-prefixed private attributes.

Before:

<PyPDFForm.lib.middleware.text.Text object at 0x10f3a2d10>

After:

Text(name='test', value=None, readonly=False, required=False, hidden=False, page_number=1, x=73.3365, y=662.692, width=232.4235, height=21.068, comb=False, multiline=False)

Changes

  • PyPDFForm/lib/middleware/base.py — added __repr__ to Widget
  • docs/inspect.md — new "Inspect individual form field widgets" section documenting pdf.widgets
  • docs/index.md — added pprint(pdf.widgets) to the quick-look example
  • tests/test_extract_middleware_attributes.py — six new tests covering Text and Checkbox repr output, attribute filtering, size propagation, and per-widget repr across a real PDF

  Widget.__repr__ now renders the class name, name, value, and all
  non-None public attributes, omitting internal bookkeeping fields.
  Documents the .widgets dict in inspect.md and adds tests covering
  repr output for Text, Checkbox, attribute filtering, and size propagation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant