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

Function calculate_active_triggers

mypy/server/update.py:763–808  ·  view source on GitHub ↗

Determine activated triggers by comparing old and new symbol tables. For example, if only the signature of function m.f is different in the new symbol table, return {' '}.

(
    manager: BuildManager,
    old_snapshots: dict[str, dict[str, SymbolSnapshot]],
    new_modules: dict[str, MypyFile | None],
)

Source from the content-addressed store, hash-verified

761
762
763def calculate_active_triggers(
764 manager: BuildManager,
765 old_snapshots: dict[str, dict[str, SymbolSnapshot]],
766 new_modules: dict[str, MypyFile | None],
767) -> set[str]:
768 """Determine activated triggers by comparing old and new symbol tables.
769
770 For example, if only the signature of function m.f is different in the new
771 symbol table, return {'<m.f>'}.
772 """
773 names: set[str] = set()
774 for id in new_modules:
775 snapshot1 = old_snapshots.get(id)
776 if snapshot1 is None:
777 names.add(id)
778 snapshot1 = {}
779 new = new_modules[id]
780 if new is None:
781 snapshot2 = snapshot_symbol_table(id, SymbolTable())
782 names.add(id)
783 else:
784 snapshot2 = snapshot_symbol_table(id, new.names)
785 diff = compare_symbol_table_snapshots(id, snapshot1, snapshot2)
786 package_nesting_level = id.count(".")
787 for item in diff.copy():
788 if item.count(".") <= package_nesting_level + 1 and item.split(".")[-1] not in (
789 "__builtins__",
790 "__file__",
791 "__name__",
792 "__package__",
793 "__doc__",
794 ):
795 # Activate catch-all wildcard trigger for top-level module changes (used for
796 # "from m import *"). This also gets triggered by changes to module-private
797 # entries, but as these unneeded dependencies only result in extra processing,
798 # it's a minor problem.
799 #
800 # TODO: Some __* names cause mistriggers. Fix the underlying issue instead of
801 # special casing them here.
802 diff.add(id + WILDCARD_TAG)
803 if item.count(".") > package_nesting_level + 1:
804 # These are for changes within classes, used by protocols.
805 diff.add(item.rsplit(".", 1)[0] + WILDCARD_TAG)
806
807 names |= diff
808 return {make_trigger(name) for name in names}
809
810
811def replace_modules_with_new_variants(

Callers 1

update_moduleMethod · 0.85

Calls 11

snapshot_symbol_tableFunction · 0.90
SymbolTableClass · 0.90
make_triggerFunction · 0.90
setClass · 0.85
splitMethod · 0.80
rsplitMethod · 0.80
getMethod · 0.45
addMethod · 0.45
countMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…