Skip to content

Commit 8396e1e

Browse files
committed
Avoid unnecessary imports to numpy.typing
1 parent 0fb7918 commit 8396e1e

File tree

3 files changed

+5
-2
lines changed
  • pybind11_stubgen/parser/mixins
  • tests/stubs/python-3.12/pybind11-v3.0.0/numpy-array-use-type-var/demo/_bindings

3 files changed

+5
-2
lines changed

pybind11_stubgen/parser/mixins/fix.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ def _add_import(self, name: QualifiedName) -> None:
168168
if module_name is None:
169169
self.report_error(NameResolutionError(name))
170170
return
171+
# Corner case: we know that annotations in numpy.typing.* are accessible from
172+
# numpy and we want to avoid unnecessary imports once these annotations are
173+
# replaced by subsequent numpy fixers.
174+
if module_name == ("numpy", "typing"):
175+
module_name = module_name.parent
171176
self.__extra_imports.add(Import(name=None, origin=module_name))
172177

173178
def _get_parent_module(self, name: QualifiedName) -> QualifiedName | None:

tests/stubs/python-3.12/pybind11-v3.0.0/numpy-array-use-type-var/demo/_bindings/eigen.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from __future__ import annotations
33
import typing
44

55
import numpy
6-
import numpy.typing
76
import scipy.sparse
87

98
__all__: list[str] = [

tests/stubs/python-3.12/pybind11-v3.0.0/numpy-array-use-type-var/demo/_bindings/numpy.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from __future__ import annotations
33
import typing
44

55
import numpy
6-
import numpy.typing
76

87
__all__: list[str] = [
98
"accept_ndarray_float64",

0 commit comments

Comments
 (0)