Override the first `module`-based import with new `imports`.
(
file: MypyFile,
module: str,
imports: list[tuple[str, None | str]],
)
| 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.""" |
no test coverage detected