Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification and Improvement of rect and rectf Handling #82

Open
0xbe7a opened this issue Nov 19, 2023 · 0 comments
Open

Clarification and Improvement of rect and rectf Handling #82

0xbe7a opened this issue Nov 19, 2023 · 0 comments

Comments

@0xbe7a
Copy link

0xbe7a commented Nov 19, 2023

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:

  1. 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.
  2. 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.
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

No branches or pull requests

1 participant