Classify each imported name and group consecutive same-kind names into buckets.
(
builder: IRBuilder,
module_id: str,
names: list[str],
as_names: list[str],
parent_is_native: bool,
)
| 502 | |
| 503 | |
| 504 | def classify_import_from( |
| 505 | builder: IRBuilder, |
| 506 | module_id: str, |
| 507 | names: list[str], |
| 508 | as_names: list[str], |
| 509 | parent_is_native: bool, |
| 510 | ) -> list[ImportFromBucket]: |
| 511 | """Classify each imported name and group consecutive same-kind names into buckets.""" |
| 512 | flat_list = [] |
| 513 | for name, as_name in zip(names, as_names): |
| 514 | submodule_id = f"{module_id}.{name}" |
| 515 | if builder.is_native_module(submodule_id) and builder.is_same_group_module(submodule_id): |
| 516 | kind = IMPORT_NATIVE_SUBMODULE |
| 517 | elif parent_is_native and submodule_id not in builder.graph: |
| 518 | kind = IMPORT_NATIVE_ATTR |
| 519 | else: |
| 520 | kind = IMPORT_NON_NATIVE |
| 521 | flat_list.append((kind, name, as_name)) |
| 522 | return group_consecutive(flat_list) |
| 523 | |
| 524 | |
| 525 | def transform_import_from_buckets( |
searching dependent graphs…