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]],
)
| 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 [ |
no test coverage detected