Skip to content

Commit 4680489

Browse files
committed
TYP: fix lazy loading and reloading once again
1 parent 3691d18 commit 4680489

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

numpy/_typing/_array_like.py

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

33
import sys
44
from collections.abc import Collection, Callable, Sequence
5-
from typing import Any, Protocol, TypeAlias, TypeVar, runtime_checkable
5+
from typing import Any, Protocol, TypeAlias, TypeVar, runtime_checkable, TYPE_CHECKING
66

77
import numpy as np
88
from numpy import (
@@ -24,6 +24,13 @@
2424
from ._nested_sequence import _NestedSequence
2525
from ._shape import _Shape
2626

27+
if TYPE_CHECKING:
28+
StringDType = np.dtypes.StringDType
29+
else:
30+
# at runtime outside of type checking importing this from numpy.dtypes
31+
# would lead to a circular import
32+
from numpy._core.multiarray import StringDType
33+
2734
_T = TypeVar("_T")
2835
_ScalarType = TypeVar("_ScalarType", bound=generic)
2936
_ScalarType_co = TypeVar("_ScalarType_co", bound=generic, covariant=True)
@@ -149,7 +156,7 @@ def __array_function__(
149156
bytes,
150157
]
151158
_ArrayLikeString_co: TypeAlias = _DualArrayLike[
152-
np.dtypes.StringDType,
159+
StringDType,
153160
str
154161
]
155162
_ArrayLikeAnyString_co: TypeAlias = _ArrayLikeStr_co | _ArrayLikeBytes_co | _ArrayLikeString_co

0 commit comments

Comments
 (0)