Return the target module path for a node.
(self, node: NodeInfo)
| 737 | self._rules.append((mod_path, matchers)) |
| 738 | |
| 739 | def route(self, node: NodeInfo) -> str: |
| 740 | """Return the target module path for a node.""" |
| 741 | # Import nodes always go to a special _imports collector |
| 742 | if node.kind == "import": |
| 743 | return "_imports" |
| 744 | |
| 745 | name = node.name |
| 746 | for mod_path, matchers in self._rules: |
| 747 | for kind, matcher in matchers: |
| 748 | if kind == "exact" and name == matcher: |
| 749 | return mod_path |
| 750 | |
| 751 | # Broad regex buckets only apply after exact-name routing. |
| 752 | for mod_path, matchers in self._rules: |
| 753 | if not matchers: |
| 754 | continue |
| 755 | for kind, matcher in matchers: |
| 756 | if kind == "regex" and matcher.search(name): |
| 757 | return mod_path |
| 758 | |
| 759 | fallback_module = self._fallback_classifier._classify(node) |
| 760 | if fallback_module != "_unclassified.py": |
| 761 | return fallback_module |
| 762 | |
| 763 | return "_unclassified.py" |
| 764 | |
| 765 | def assign_all(self, nodes: List[NodeInfo]) -> None: |
| 766 | """Assign target_module to all nodes in-place.""" |