Skip to content

Conversation

@jorenham
Copy link
Member

@jorenham jorenham commented Oct 24, 2025

This follows #199. See the added # NOTE for why we cannot annotate the array-like constructor cases.

I didn't see any mention of np.bool_ scalars in #199, only floating and integer ones. So I take it that QuadPrecision.__new__ does not accept np.bool_ instances then?

@override
def __getitem__(self, key: Never, /) -> Self: ... # type: ignore[override]

# NOTE: Until `QuadPrecision` will become a subclass of `np.generic`, this class cannot
Copy link
Member

Choose a reason for hiding this comment

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

In [5]: issubclass(npq.QuadPrecDType().type, np.generic)
Out[5]: True

In [6]: npq.QuadPrecDType().type
Out[6]: numpy_quaddtype.QuadPrecision

In [7]: issubclass(npq.QuadPrecision, np.generic)
Out[7]: True

I think it is as Quadprecision already subclassing the np.floating

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! I'll open a separate PR for that then.

Copy link
Member Author

@jorenham jorenham Oct 24, 2025

Choose a reason for hiding this comment

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

What does numpy_quaddtype.QuadPrecision.mro() return? (sorry I wasn't able to get it to build locally) Because there's a chance that there's some __subclasscheck__ trickery going on.

Copy link
Member

Choose a reason for hiding this comment

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

In [11]: npq.QuadPrecision.mro()
Out[11]: 
[numpy_quaddtype.QuadPrecision,
 numpy.floating,
 numpy.inexact,
 numpy.number,
 numpy.generic,
 object]

Building it requires the numpy build from source right now :)

@SwayamInSync
Copy link
Member

So I take it that QuadPrecision.new does not accept np.bool_ instances then?

I think we should accept this right :) @jorenham I'll do the PR for this, you can assume it accept

cc: @ngoldbaum

@jorenham jorenham changed the title TYP: Allow passing floating and integer scalars to QuadPrecision.__new__ TYP: Allow passing floating, integer, and bool_ scalars to QuadPrecision.__new__ Oct 24, 2025
@SwayamInSync
Copy link
Member

@jorenham is this ready?
The new PRs I've added to address your comments and issues would not impact this?

@SwayamInSync
Copy link
Member

Also for the part that QuadPrecision is type-safe (it subclassing np.generic)

@jorenham
Copy link
Member Author

Yea this is fine to merge. I want to address the np.generic subclass stuff in a follow-up, since that will probably be a bit more involved

@SwayamInSync
Copy link
Member

Cool thanks @jorenham merging this in

@SwayamInSync SwayamInSync merged commit 9a26823 into numpy:main Oct 25, 2025
11 checks passed
@jorenham jorenham deleted the quaddtype/update-stubs-after-gh-199 branch October 25, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants