python-poppler
python-poppler copied to clipboard
Clarification and Improvement of `rect` and `rectf` Handling
While using PyLance for local development, I've encountered an inconsistency in the Python bindings related to the handling of Rectangle objects (rect
and rectf
). Specifically, the constructor for a Rectangle can accept either four floats or four integers, creating a rect
or rectf
respectively. However, this distinction becomes unclear when using certain functions like Page.text()
that specifically require a rectf
for the bounding box.
Currently, the bindings do not clearly differentiate between a rect
and a rectf
from the perspective of a developer working with Rectangles. This leads to confusion, especially since there's no visible difference in the Python code.
Additionally, there's an issue with PyLance when attempting to construct a Rectangle using float values. PyLance reports an error because the default arguments for the constructor are integers, causing type conflicts.
Proposed Solutions:
To address these issues, I suggest one of the following approaches:
-
Document and Distinguish
rect
andrectf
Types:- Update the documentation to clearly differentiate between
rect
andrectf
. - Overload the Rectangle constructor to include both
(x: float, y: float, w: float, h: float)
and(x: int, y: int, w: int, h: int)
. This provides explicit constructors for each type and makes it clear to the developer which type they are working with.
- Update the documentation to clearly differentiate between
-
Transparent Handling of Type Differences:
- Modify the Rectangle constructor to handle both
int
andfloat
types seamlessly. This approach would abstract the complexity from the developer, allowing for more flexible and intuitive usage of the API.
- Modify the Rectangle constructor to handle both