add_import
Add a complete import line to a source file, skip exact duplicates, and place it in the correct sorted import group. Use when importing something not yet present.
Instructions
Add an import line, skipping an exact duplicate. It goes into the group
of imports it belongs with (same package, standard library or not,
relative or not), at its sorted place when the group is sorted, else
after the group's last import. A comment heading the group stays first
(a next-line directive stays on its import), and so do Python from __future__ imports. With no fitting group it goes after the last
import, and a first import after the preamble.
Use this when: importing something the file does not import yet. Don't use this when: adding a name to an existing import (add_import_name).
Example: import_text="from typing import Optional"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Absolute path to the source or config file. | |
| import_text | Yes | Complete import line in the file's language (e.g. 'import os', '#include <stdlib.h>'); in Go a bare spec ('"fmt"') works too. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |