|
37 | 37 | from typing_extensions import assert_never, Literal, Protocol, Self
|
38 | 38 |
|
39 | 39 | from .error_code import ErrorCode
|
40 |
| -from .safe import all_of_type |
41 | 40 | from .stacked_scopes import (
|
42 | 41 | AbstractConstraint,
|
43 | 42 | AndConstraint,
|
@@ -1254,41 +1253,45 @@ def _maybe_perform_call(
|
1254 | 1253 | args = []
|
1255 | 1254 | kwargs = {}
|
1256 | 1255 | for definitely_present, composite in actual_args.positionals:
|
1257 |
| - if definitely_present and isinstance(composite.value, KnownValue): |
1258 |
| - args.append(composite.value.val) |
1259 |
| - else: |
| 1256 | + if not definitely_present: |
| 1257 | + return None |
| 1258 | + arg = _extract_known_value(composite.value) |
| 1259 | + if arg is None: |
1260 | 1260 | return None
|
| 1261 | + args.append(arg.val) |
1261 | 1262 | if actual_args.star_args is not None:
|
1262 | 1263 | values = concrete_values_from_iterable(
|
1263 | 1264 | actual_args.star_args, ctx.can_assign_ctx
|
1264 | 1265 | )
|
1265 |
| - if isinstance(values, collections.abc.Sequence) and all_of_type( |
1266 |
| - values, KnownValue |
1267 |
| - ): |
1268 |
| - args += [val.val for val in values] |
1269 |
| - else: |
| 1266 | + if not isinstance(values, collections.abc.Sequence): |
1270 | 1267 | return None
|
| 1268 | + for args_val in values: |
| 1269 | + arg = _extract_known_value(args_val) |
| 1270 | + if arg is None: |
| 1271 | + return None |
| 1272 | + args.append(arg.val) |
1271 | 1273 | for kwarg, (required, composite) in actual_args.keywords.items():
|
1272 | 1274 | if not required:
|
1273 | 1275 | return None
|
1274 |
| - if isinstance(composite.value, KnownValue): |
1275 |
| - kwargs[kwarg] = composite.value.val |
1276 |
| - else: |
| 1276 | + kwarg_value = _extract_known_value(composite.value) |
| 1277 | + if kwarg_value is None: |
1277 | 1278 | return None
|
| 1279 | + kwargs[kwarg] = kwarg_value.val |
1278 | 1280 | if actual_args.star_kwargs is not None:
|
1279 | 1281 | value = replace_known_sequence_value(actual_args.star_kwargs)
|
1280 | 1282 | if isinstance(value, DictIncompleteValue):
|
1281 | 1283 | for pair in value.kv_pairs:
|
| 1284 | + if pair.is_many or not pair.is_required: |
| 1285 | + return None |
| 1286 | + key_val = _extract_known_value(pair.key) |
| 1287 | + value_val = _extract_known_value(pair.value) |
1282 | 1288 | if (
|
1283 |
| - pair.is_required |
1284 |
| - and not pair.is_many |
1285 |
| - and isinstance(pair.key, KnownValue) |
1286 |
| - and isinstance(pair.key.val, str) |
1287 |
| - and isinstance(pair.value, KnownValue) |
| 1289 | + key_val is None |
| 1290 | + or value_val is None |
| 1291 | + or not isinstance(key_val.val, str) |
1288 | 1292 | ):
|
1289 |
| - kwargs[pair.key.val] = pair.value.val |
1290 |
| - else: |
1291 | 1293 | return None
|
| 1294 | + kwargs[key_val.val] = value_val.val |
1292 | 1295 | else:
|
1293 | 1296 | return None
|
1294 | 1297 |
|
@@ -2518,3 +2521,11 @@ def decompose_union(
|
2518 | 2521 | ), f"all union members matched between {expected_type} and {parent_value}"
|
2519 | 2522 | return bounds_map, union_used_any, unite_values(*remaining_values)
|
2520 | 2523 | return None
|
| 2524 | + |
| 2525 | + |
| 2526 | +def _extract_known_value(val: Value) -> Optional[KnownValue]: |
| 2527 | + if isinstance(val, AnnotatedValue): |
| 2528 | + val = val.value |
| 2529 | + if isinstance(val, KnownValue): |
| 2530 | + return val |
| 2531 | + return None |
0 commit comments