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

Class SuggestionEngine

mypy/suggestions.py:245–787  ·  view source on GitHub ↗

Engine for finding call sites and suggesting signatures.

Source from the content-addressed store, hash-verified

243
244
245class SuggestionEngine:
246 """Engine for finding call sites and suggesting signatures."""
247
248 def __init__(
249 self,
250 fgmanager: FineGrainedBuildManager,
251 *,
252 json: bool,
253 no_errors: bool = False,
254 no_any: bool = False,
255 flex_any: float | None = None,
256 use_fixme: str | None = None,
257 max_guesses: int | None = None,
258 ) -> None:
259 self.fgmanager = fgmanager
260 self.manager = fgmanager.manager
261 self.plugin = self.manager.plugin
262 self.graph = fgmanager.graph
263 self.finder = SourceFinder(self.manager.fscache, self.manager.options)
264
265 self.give_json = json
266 self.no_errors = no_errors
267 self.flex_any = flex_any
268 if no_any:
269 self.flex_any = 1.0
270
271 self.max_guesses = max_guesses or 64
272 self.use_fixme = use_fixme
273
274 def suggest(self, function: str) -> str:
275 """Suggest an inferred type for function."""
276 mod, func_name, node = self.find_node(function)
277
278 with self.restore_after(mod):
279 with self.with_export_types():
280 suggestion = self.get_suggestion(mod, node)
281
282 if self.give_json:
283 return self.json_suggestion(mod, func_name, node, suggestion)
284 else:
285 return self.format_signature(suggestion)
286
287 def suggest_callsites(self, function: str) -> str:
288 """Find a list of call sites of function."""
289 mod, _, node = self.find_node(function)
290 with self.restore_after(mod):
291 callsites, _ = self.get_callsites(node)
292
293 return "\n".join(
294 dedup(
295 [
296 f"{path}:{line}: {self.format_args(arg_kinds, arg_names, arg_types)}"
297 for path, line, arg_kinds, _, arg_names, arg_types in callsites
298 ]
299 )
300 )
301
302 @contextmanager

Callers 1

cmd_suggestMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…