MCPcopy Create free account
hub / github.com/numpy/numpy / _override_imports

Function _override_imports

numpy/typing/mypy_plugin.py:136–149  ·  view source on GitHub ↗

Override the first `module`-based import with new `imports`.

(
        file: MypyFile,
        module: str,
        imports: list[tuple[str, None | str]],
    )

Source from the content-addressed store, hash-verified

134 f"with the following id: {id!r}")
135
136 def _override_imports(
137 file: MypyFile,
138 module: str,
139 imports: list[tuple[str, None | str]],
140 ) -> None:
141 """Override the first `module`-based import with new `imports`."""
142 # Construct a new `from module import y` statement
143 import_obj = ImportFrom(module, 0, names=imports)
144 import_obj.is_top_level = True
145
146 # Replace the first `module`-based import statement with `import_obj`
147 for lst in [file.defs, file.imports]: # type: list[Statement]
148 i = _index(lst, module)
149 lst[i] = import_obj
150
151 class _NumpyPlugin(Plugin):
152 """A mypy plugin for handling versus numpy-specific typing tasks."""

Callers 1

get_additional_depsMethod · 0.85

Calls 1

_indexFunction · 0.85

Tested by

no test coverage detected