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

feat(types): Use typing.SupportsInt and typing.SupportsFloat #5540

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

InvincibleRMC
Copy link
Contributor

Description

Since int and floats by default can convert from __int__ and __float__ probably mark the input type.

Closes #5158

Suggested changelog entry:

    Adds support for `typing.SupportsInt` and `typing.SupportsFloat`

InvincibleRMC and others added 8 commits February 21, 2025 17:33
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Copy link
Contributor

@timohl timohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting addition.
You might be still working on this, but I left some comments.

Is the change in attr_with_type_hint related to the issue this PR fixes or is this a fix for another issue introduces by my changes from adding io_name?
Were there any failing tests for that or have you added some?
If not, adding tests would be great. (I have not gone through all the test_... changes yet).

@InvincibleRMC
Copy link
Contributor Author

Is the change in attr_with_type_hint related to the issue this PR fixes or is this a fix for another issue introduces by my changes from adding io_name?

Yes this more related to the io_name changes but, wasn't uncovered since the attr_with_type_hint tests were written without any type that change based on return type. Since int was the old type being used in them making this change exposed this error.

InvincibleRMC and others added 9 commits February 21, 2025 19:03
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
@InvincibleRMC
Copy link
Contributor Author

InvincibleRMC commented Feb 22, 2025

@timohl One other thing that came up is what to do about bool. Since the bool caster also works and there is no typing.SupportsBool. The common suggestions are use the object type or create a custom protocol. However pybind does not currently support protocols. I'm a little hesitant to broaden the type but maybe something like typing.Annotated[object, "bool"] might be a good middle ground for the input type.

InvincibleRMC and others added 2 commits February 22, 2025 17:09
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
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.

[FEATURE REQUEST]: typing.SupportsInt type hint
2 participants