Produces the lowest bound of the 'replace' signatures of multiple dataclasses.
(sigs: list[CallableType])
| 1043 | # and leave this to the regular machinery of resolving a union of callables |
| 1044 | # (https://github.com/python/mypy/issues/15457) |
| 1045 | def _meet_replace_sigs(sigs: list[CallableType]) -> CallableType: |
| 1046 | """ |
| 1047 | Produces the lowest bound of the 'replace' signatures of multiple dataclasses. |
| 1048 | """ |
| 1049 | args = { |
| 1050 | name: (typ, kind) |
| 1051 | for name, typ, kind in zip(sigs[0].arg_names, sigs[0].arg_types, sigs[0].arg_kinds) |
| 1052 | } |
| 1053 | |
| 1054 | for sig in sigs[1:]: |
| 1055 | sig_args = { |
| 1056 | name: (typ, kind) |
| 1057 | for name, typ, kind in zip(sig.arg_names, sig.arg_types, sig.arg_kinds) |
| 1058 | } |
| 1059 | for name in (*args.keys(), *sig_args.keys()): |
| 1060 | sig_typ, sig_kind = args.get(name, (UninhabitedType(), ARG_NAMED_OPT)) |
| 1061 | sig2_typ, sig2_kind = sig_args.get(name, (UninhabitedType(), ARG_NAMED_OPT)) |
| 1062 | args[name] = ( |
| 1063 | meet_types(sig_typ, sig2_typ), |
| 1064 | ARG_NAMED_OPT if sig_kind == sig2_kind == ARG_NAMED_OPT else ARG_NAMED, |
| 1065 | ) |
| 1066 | |
| 1067 | return sigs[0].copy_modified( |
| 1068 | arg_names=list(args.keys()), |
| 1069 | arg_types=[typ for typ, _ in args.values()], |
| 1070 | arg_kinds=[kind for _, kind in args.values()], |
| 1071 | ) |
| 1072 | |
| 1073 | |
| 1074 | def replace_function_sig_callback(ctx: FunctionSigContext) -> CallableType: |
no test coverage detected
searching dependent graphs…