Skip to content

Commit be61071

Browse files
committed
ENH: Make numpy.iinfo and numpy.finfo generic at runtime
1 parent bb462da commit be61071

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

numpy/_core/getlimits.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
__all__ = ['finfo', 'iinfo']
55

6+
import types
67
import warnings
78

89
from .._utils import set_module
@@ -487,6 +488,8 @@ class finfo:
487488

488489
_finfo_cache = {}
489490

491+
__class_getitem__ = classmethod(types.GenericAlias)
492+
490493
def __new__(cls, dtype):
491494
try:
492495
obj = cls._finfo_cache.get(dtype) # most common path
@@ -689,6 +692,8 @@ class iinfo:
689692
_min_vals = {}
690693
_max_vals = {}
691694

695+
__class_getitem__ = classmethod(types.GenericAlias)
696+
692697
def __init__(self, int_type):
693698
try:
694699
self.dtype = numeric.dtype(int_type)

numpy/_core/tests/test_getlimits.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" Test functions for limits module.
22
33
"""
4+
import types
45
import warnings
56
import numpy as np
67
import pytest
@@ -192,3 +193,11 @@ def test_plausible_finfo():
192193
assert_(info.nmant > 1)
193194
assert_(info.minexp < -1)
194195
assert_(info.maxexp > 1)
196+
197+
198+
class TestRuntimeSubscriptable:
199+
def test_finfo_generic(self):
200+
assert isinstance(np.finfo[np.float64], types.GenericAlias)
201+
202+
def test_iinfo_generic(self):
203+
assert isinstance(np.iinfo[np.int_], types.GenericAlias)

0 commit comments

Comments
 (0)