Skip to content

Commit b664fe0

Browse files
authored
Merge pull request numpy#27152 from jorenham/typing/ufunc-stubs-vs-runtime
TYP: Simpllified ufunc imports in ``numpy._typing``
2 parents 99d319e + 3306eca commit b664fe0

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

numpy/_typing/__init__.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
from __future__ import annotations
44

5-
from .. import ufunc
65
from .._utils import set_module
7-
from typing import TYPE_CHECKING, final
6+
from typing import final
87

98

109
@final # Disallow the creation of arbitrary `NBitBase` subclasses
@@ -206,19 +205,10 @@ class _8Bit(_16Bit): # type: ignore[misc]
206205
_UnknownType as _UnknownType,
207206
)
208207

209-
if TYPE_CHECKING:
210-
from ._ufunc import (
211-
_UFunc_Nin1_Nout1 as _UFunc_Nin1_Nout1,
212-
_UFunc_Nin2_Nout1 as _UFunc_Nin2_Nout1,
213-
_UFunc_Nin1_Nout2 as _UFunc_Nin1_Nout2,
214-
_UFunc_Nin2_Nout2 as _UFunc_Nin2_Nout2,
215-
_GUFunc_Nin2_Nout1 as _GUFunc_Nin2_Nout1,
216-
)
217-
else:
218-
# Declare the (type-check-only) ufunc subclasses as ufunc aliases during
219-
# runtime; this helps autocompletion tools such as Jedi (numpy/numpy#19834)
220-
_UFunc_Nin1_Nout1 = ufunc
221-
_UFunc_Nin2_Nout1 = ufunc
222-
_UFunc_Nin1_Nout2 = ufunc
223-
_UFunc_Nin2_Nout2 = ufunc
224-
_GUFunc_Nin2_Nout1 = ufunc
208+
from ._ufunc import (
209+
_UFunc_Nin1_Nout1 as _UFunc_Nin1_Nout1,
210+
_UFunc_Nin2_Nout1 as _UFunc_Nin2_Nout1,
211+
_UFunc_Nin1_Nout2 as _UFunc_Nin1_Nout2,
212+
_UFunc_Nin2_Nout2 as _UFunc_Nin2_Nout2,
213+
_GUFunc_Nin2_Nout1 as _GUFunc_Nin2_Nout1,
214+
)

numpy/_typing/_ufunc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .. import ufunc
2+
3+
_UFunc_Nin1_Nout1 = ufunc
4+
_UFunc_Nin2_Nout1 = ufunc
5+
_UFunc_Nin1_Nout2 = ufunc
6+
_UFunc_Nin2_Nout2 = ufunc
7+
_GUFunc_Nin2_Nout1 = ufunc

0 commit comments

Comments
 (0)