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

Class Overloaded

mypy/types.py:2666–2747  ·  view source on GitHub ↗

Overloaded function type T1, ... Tn, where each Ti is CallableType. The variant to call is chosen based on static argument types. Overloaded function types can only be defined in stub files, and thus there is no explicit runtime dispatch implementation.

Source from the content-addressed store, hash-verified

2664
2665
2666class Overloaded(FunctionLike):
2667 """Overloaded function type T1, ... Tn, where each Ti is CallableType.
2668
2669 The variant to call is chosen based on static argument
2670 types. Overloaded function types can only be defined in stub
2671 files, and thus there is no explicit runtime dispatch
2672 implementation.
2673 """
2674
2675 __slots__ = ("_items",)
2676
2677 _items: list[CallableType] # Must not be empty
2678
2679 def __init__(self, items: list[CallableType]) -> None:
2680 super().__init__(items[0].line, items[0].column)
2681 self._items = items
2682 self.fallback = items[0].fallback
2683
2684 @property
2685 def items(self) -> list[CallableType]:
2686 return self._items
2687
2688 def name(self) -> str | None:
2689 return self.get_name()
2690
2691 def is_type_obj(self) -> bool:
2692 # All the items must have the same type object status, so it's
2693 # sufficient to query only (any) one of them.
2694 return self._items[0].is_type_obj()
2695
2696 def type_object(self) -> mypy.nodes.TypeInfo:
2697 # All the items must have the same type object, so it's sufficient to
2698 # query only (any) one of them.
2699 return self._items[0].type_object()
2700
2701 def with_name(self, name: str) -> Overloaded:
2702 ni: list[CallableType] = []
2703 for it in self._items:
2704 ni.append(it.with_name(name))
2705 return Overloaded(ni)
2706
2707 def get_name(self) -> str | None:
2708 return self._items[0].name
2709
2710 def with_unpacked_kwargs(self) -> Overloaded:
2711 if any(i.unpack_kwargs for i in self.items):
2712 return Overloaded([i.with_unpacked_kwargs() for i in self.items])
2713 return self
2714
2715 def accept(self, visitor: TypeVisitor[T]) -> T:
2716 return visitor.visit_overloaded(self)
2717
2718 def __hash__(self) -> int:
2719 return hash(tuple(self.items))
2720
2721 def __eq__(self, other: object) -> bool:
2722 if not isinstance(other, Overloaded):
2723 return NotImplemented

Callers 15

check_self_argFunction · 0.90
add_class_tvarsFunction · 0.90
bind_self_fastFunction · 0.90
apply_signature_hookMethod · 0.90
bind_selfFunction · 0.90
function_typeFunction · 0.90

Calls

no outgoing calls

Tested by 2

ovMethod · 0.72
make_overloadMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…