You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 and rectf Types:
Update the documentation to clearly differentiate between rect and rectf.
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.
Transparent Handling of Type Differences:
Modify the Rectangle constructor to handle both int and float types seamlessly. This approach would abstract the complexity from the developer, allowing for more flexible and intuitive usage of the API.
The text was updated successfully, but these errors were encountered:
While using PyLance for local development, I've encountered an inconsistency in the Python bindings related to the handling of Rectangle objects (
rect
andrectf
). Specifically, the constructor for a Rectangle can accept either four floats or four integers, creating arect
orrectf
respectively. However, this distinction becomes unclear when using certain functions likePage.text()
that specifically require arectf
for the bounding box.Currently, the bindings do not clearly differentiate between a
rect
and arectf
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:rect
andrectf
.(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.Transparent Handling of Type Differences:
int
andfloat
types seamlessly. This approach would abstract the complexity from the developer, allowing for more flexible and intuitive usage of the API.The text was updated successfully, but these errors were encountered: