MCPcopy
hub / github.com/python/mypy / combine_arg_names

Function combine_arg_names

mypy/join.py:839–867  ·  view source on GitHub ↗

Produces a list of argument names compatible with both callables. For example, suppose 't' and 's' have the following signatures: - t: (a: int, b: str, X: str) -> None - s: (a: int, b: str, Y: str) -> None This function would return ["a", "b", None]. This information is then u

(
    t: CallableType | Parameters, s: CallableType | Parameters
)

Source from the content-addressed store, hash-verified

837
838
839def combine_arg_names(
840 t: CallableType | Parameters, s: CallableType | Parameters
841) -> list[str | None]:
842 """Produces a list of argument names compatible with both callables.
843
844 For example, suppose 't' and 's' have the following signatures:
845
846 - t: (a: int, b: str, X: str) -> None
847 - s: (a: int, b: str, Y: str) -> None
848
849 This function would return ["a", "b", None]. This information
850 is then used above to compute the join of t and s, which results
851 in a signature of (a: int, b: str, str) -> None.
852
853 Note that the third argument's name is omitted and 't' and 's'
854 are both valid subtypes of this inferred signature.
855
856 Precondition: is_similar_types(t, s) is true.
857 """
858 num_args = len(t.arg_types)
859 new_names = []
860 for i in range(num_args):
861 t_name = t.arg_names[i]
862 s_name = s.arg_names[i]
863 if t_name == s_name or t.arg_kinds[i].is_named() or s.arg_kinds[i].is_named():
864 new_names.append(t_name)
865 else:
866 new_names.append(None)
867 return new_names
868
869
870def object_from_instance(instance: Instance) -> Instance:

Callers 3

visit_parametersMethod · 0.85
join_similar_callablesFunction · 0.85

Calls 4

lenFunction · 0.85
rangeClass · 0.85
is_namedMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…