Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: Fix DTypeLike runtime type-checker support (#31425)#31426

Merged
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
jorenham:backport-31425
May 13, 2026
Merged

TYP: Fix DTypeLike runtime type-checker support (#31425)#31426
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
jorenham:backport-31425

Conversation

@jorenham
Copy link
Copy Markdown
Member

Backport of #31425.


Runtime type-checkers like beartype currently aren't able to check if something is an instance of numpy.typing.DTypeLike because not all protocols in the union type aren't runtime checkable (see https://github.com/mikedh/trimesh/actions/runs/25796361932/job/75774562690?pr=2541 for example). The fix is to to add a @runtime_checkable to the _HasNumPyDType protocol.


On the 2.4 branch the _HasDType protocol is also missing a @runtime_checkable (

class _HasDType(Protocol[_DTypeT_co]):
@property
def dtype(self) -> _DTypeT_co: ...
class _HasNumPyDType(Protocol[_DTypeT_co]):
@property
def __numpy_dtype__(self, /) -> _DTypeT_co: ...
). So it should also be added there when backporting this, as well as importing runtime_checkable from typing.


No AI

@jorenham jorenham added this to the 2.4.5 release milestone May 13, 2026
@jorenham jorenham added 08 - Backport Used to tag backport PRs 41 - Static typing labels May 13, 2026
@charris charris merged commit be6123a into numpy:maintenance/2.4.x May 13, 2026
74 of 75 checks passed
@charris
Copy link
Copy Markdown
Member

charris commented May 13, 2026

Thanks Joren.

@jorenham jorenham deleted the backport-31425 branch May 13, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

08 - Backport Used to tag backport PRs 41 - Static typing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants