MCPcopy Create free account
hub / github.com/Snapchat/Valdi / _diff_classes

Function _diff_classes

tools/api_surface/check_api_surface.py:119–166  ·  view source on GitHub ↗

Compare class definitions. Returns (warnings, errors).

(baseline: dict, current: dict)

Source from the content-addressed store, hash-verified

117 if b_props[prop] != c_props[prop]:
118 warnings.append(
119 f"Changed '{name}.{prop}':\n"
120 f" baseline: {b_props[prop]}\n"
121 f" current: {c_props[prop]}"
122 )
123
124 return warnings, errors
125
126
127def _diff_classes(baseline: dict, current: dict):
128 """Compare class definitions. Returns (warnings, errors)."""
129 warnings = []
130 errors = []
131
132 baseline_names = set(baseline.keys())
133 current_names = set(current.keys())
134
135 for name in sorted(baseline_names - current_names):
136 errors.append(f"Removed class '{name}'")
137
138 for name in sorted(current_names - baseline_names):
139 warnings.append(f"Added class '{name}'")
140
141 for name in sorted(baseline_names & current_names):
142 b_cls = baseline[name]
143 c_cls = current[name]
144
145 # Check extends
146 if b_cls.get("extends") != c_cls.get("extends"):
147 warnings.append(
148 f"Changed '{name}' extends:\n"
149 f" baseline: {b_cls.get('extends')}\n"
150 f" current: {c_cls.get('extends')}"
151 )
152
153 # Check methods
154 b_methods = b_cls.get("methods", {})
155 c_methods = c_cls.get("methods", {})
156
157 b_keys = set(b_methods.keys())
158 c_keys = set(c_methods.keys())
159
160 for method in sorted(b_keys - c_keys):
161 errors.append(f"Removed '{name}.{method}' (was: {b_methods[method]})")
162
163 for method in sorted(c_keys - b_keys):
164 warnings.append(f"Added '{name}.{method}': {c_methods[method]}")
165
166 for method in sorted(b_keys & c_keys):
167 if b_methods[method] != c_methods[method]:
168 warnings.append(
169 f"Changed '{name}.{method}':\n"

Callers 1

checkFunction · 0.85

Calls 4

keysMethod · 0.65
appendMethod · 0.65
getMethod · 0.65
setFunction · 0.50

Tested by

no test coverage detected