Consolidate submodules if count exceeds threshold. Args: modules: Set of full module paths (e.g., {"urllib.request", "urllib.parse", "xml.dom", "xml.sax"}) threshold: If submodules > threshold, consolidate to parent Returns: Dict mapping display_name -> set of origi
(
modules: set[str], threshold: int = 3
)
| 1537 | |
| 1538 | |
| 1539 | def _consolidate_submodules( |
| 1540 | modules: set[str], threshold: int = 3 |
| 1541 | ) -> dict[str, set[str]]: |
| 1542 | """Consolidate submodules if count exceeds threshold. |
| 1543 | |
| 1544 | Args: |
| 1545 | modules: Set of full module paths (e.g., {"urllib.request", "urllib.parse", "xml.dom", "xml.sax"}) |
| 1546 | threshold: If submodules > threshold, consolidate to parent |
| 1547 | |
| 1548 | Returns: |
| 1549 | Dict mapping display_name -> set of original module paths |
| 1550 | e.g., {"urllib.request": {"urllib.request"}, "xml": {"xml.dom", "xml.sax", "xml.etree", "xml.parsers"}} |
| 1551 | """ |
| 1552 | # Group by top-level package |
| 1553 | by_package: dict[str, set[str]] = {} |
| 1554 | for mod in modules: |
| 1555 | parts = mod.split(".") |
| 1556 | top = parts[0] |
| 1557 | if top not in by_package: |
| 1558 | by_package[top] = set() |
| 1559 | by_package[top].add(mod) |
| 1560 | |
| 1561 | result: dict[str, set[str]] = {} |
| 1562 | for top, submods in by_package.items(): |
| 1563 | if len(submods) > threshold: |
| 1564 | # Consolidate to top-level |
| 1565 | result[top] = submods |
| 1566 | else: |
| 1567 | # Keep individual |
| 1568 | for mod in submods: |
| 1569 | result[mod] = {mod} |
| 1570 | |
| 1571 | return result |
| 1572 | |
| 1573 | |
| 1574 | # Modules that are used everywhere - show but don't expand their dependents |