MCPcopy Index your code
hub / github.com/python/mypy / classify_import_from

Function classify_import_from

mypyc/irbuild/statement.py:504–522  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

502
503
504def 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
525def transform_import_from_buckets(

Calls 5

zipFunction · 0.85
group_consecutiveFunction · 0.85
is_same_group_moduleMethod · 0.80
appendMethod · 0.80
is_native_moduleMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…