Skip to content

Commit ce6fb12

Browse files
Merge pull request #1 from radarhere/bug/compat/numpy1.20
Do not import numpy.typing unless TYPE_CHECKING
2 parents b4ee967 + 8b8fc18 commit ce6fb12

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/PIL/_typing.py

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

33
import os
44
import sys
5-
from typing import Any, Protocol, Sequence, TypeVar, Union
5+
from typing import TYPE_CHECKING, Any, Protocol, Sequence, TypeVar, Union
66

7-
try:
8-
import numpy.typing as npt
7+
if TYPE_CHECKING:
8+
try:
9+
import numpy.typing as npt
910

10-
NumpyArray = npt.NDArray[Any] # requires numpy>=1.21
11-
except (ImportError, AttributeError):
12-
pass
11+
NumpyArray = npt.NDArray[Any] # requires numpy>=1.21
12+
except (ImportError, AttributeError):
13+
pass
1314

1415
if sys.version_info >= (3, 10):
1516
from typing import TypeGuard

0 commit comments

Comments
 (0)