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

Function _meet_replace_sigs

mypy/plugins/dataclasses.py:1045–1071  ·  view source on GitHub ↗

Produces the lowest bound of the 'replace' signatures of multiple dataclasses.

(sigs: list[CallableType])

Source from the content-addressed store, hash-verified

1043# and leave this to the regular machinery of resolving a union of callables
1044# (https://github.com/python/mypy/issues/15457)
1045def _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
1074def replace_function_sig_callback(ctx: FunctionSigContext) -> CallableType:

Callers 1

Calls 8

UninhabitedTypeClass · 0.90
meet_typesFunction · 0.90
zipFunction · 0.85
listClass · 0.85
keysMethod · 0.80
valuesMethod · 0.80
getMethod · 0.45
copy_modifiedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…