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

Method get_args

mypy/suggestions.py:345–397  ·  view source on GitHub ↗

Produce a list of type suggestions for each argument type.

(
        self,
        is_method: bool,
        base: CallableType,
        defaults: list[Type | None],
        callsites: list[Callsite],
        uses: list[list[Type]],
    )

Source from the content-addressed store, hash-verified

343 return self.get_trivial_type(fdef)
344
345 def get_args(
346 self,
347 is_method: bool,
348 base: CallableType,
349 defaults: list[Type | None],
350 callsites: list[Callsite],
351 uses: list[list[Type]],
352 ) -> list[list[Type]]:
353 """Produce a list of type suggestions for each argument type."""
354 types: list[list[Type]] = []
355 for i in range(len(base.arg_kinds)):
356 # Make self args Any but this will get overridden somewhere in the checker
357 if i == 0 and is_method:
358 types.append([AnyType(TypeOfAny.suggestion_engine)])
359 continue
360
361 all_arg_types = []
362 for call in callsites:
363 for typ in call.arg_types[i - is_method]:
364 # Collect all the types except for implicit anys
365 if not is_implicit_any(typ):
366 all_arg_types.append(typ)
367 all_use_types = []
368 for typ in uses[i]:
369 # Collect all the types except for implicit anys
370 if not is_implicit_any(typ):
371 all_use_types.append(typ)
372 # Add in any default argument types
373 default = defaults[i]
374 if default:
375 all_arg_types.append(default)
376 if all_use_types:
377 all_use_types.append(default)
378
379 arg_types = []
380
381 if all_arg_types and all(
382 isinstance(get_proper_type(tp), NoneType) for tp in all_arg_types
383 ):
384 arg_types.append(
385 UnionType.make_union([all_arg_types[0], AnyType(TypeOfAny.explicit)])
386 )
387 elif all_arg_types:
388 arg_types.extend(generate_type_combinations(all_arg_types))
389 else:
390 arg_types.append(AnyType(TypeOfAny.explicit))
391
392 if all_use_types:
393 # This is a meet because the type needs to be compatible with all the uses
394 arg_types.append(meet_type_list(all_use_types))
395
396 types.append(arg_types)
397 return types
398
399 def get_default_arg_types(self, fdef: FuncDef) -> list[Type | None]:
400 return [

Callers 1

get_guessesMethod · 0.95

Calls 12

AnyTypeClass · 0.90
get_proper_typeFunction · 0.90
meet_type_listFunction · 0.90
rangeClass · 0.85
lenFunction · 0.85
is_implicit_anyFunction · 0.85
allFunction · 0.85
isinstanceFunction · 0.85
appendMethod · 0.80
make_unionMethod · 0.80
extendMethod · 0.80

Tested by

no test coverage detected