MCPcopy Index your code
hub / github.com/python/cpython / _GenericAlias

Class _GenericAlias

Lib/typing.py:1365–1584  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1363
1364
1365class _GenericAlias(_BaseGenericAlias, _root=True):
1366 # The type of parameterized generics.
1367 #
1368 # That is, for example, `type(List[int])` is `_GenericAlias`.
1369 #
1370 # Objects which are instances of this class include:
1371 # * Parameterized container types, e.g. `Tuple[int]`, `List[int]`.
1372 # * Note that native container types, e.g. `tuple`, `list`, use
1373 # `types.GenericAlias` instead.
1374 # * Parameterized classes:
1375 # class C[T]: pass
1376 # # C[int] is a _GenericAlias
1377 # * `Callable` aliases, generic `Callable` aliases, and
1378 # parameterized `Callable` aliases:
1379 # T = TypeVar('T')
1380 # # _CallableGenericAlias inherits from _GenericAlias.
1381 # A = Callable[[], None] # _CallableGenericAlias
1382 # B = Callable[[T], None] # _CallableGenericAlias
1383 # C = B[int] # _CallableGenericAlias
1384 # * Parameterized `Final`, `ClassVar`, `TypeForm`, `TypeGuard`, and `TypeIs`:
1385 # # All _GenericAlias
1386 # Final[int]
1387 # ClassVar[float]
1388 # TypeForm[bytes]
1389 # TypeGuard[bool]
1390 # TypeIs[range]
1391
1392 def __init__(self, origin, args, *, inst=True, name=None):
1393 super().__init__(origin, inst=inst, name=name)
1394 if not isinstance(args, tuple):
1395 args = (args,)
1396 self.__args__ = tuple(... if a is _TypingEllipsis else
1397 a for a in args)
1398 enforce_default_ordering = origin in (Generic, Protocol)
1399 self.__parameters__ = _collect_type_parameters(
1400 args,
1401 enforce_default_ordering=enforce_default_ordering,
1402 )
1403 if not name:
1404 self.__module__ = origin.__module__
1405
1406 def __eq__(self, other):
1407 if not isinstance(other, _GenericAlias):
1408 return NotImplemented
1409 return (self.__origin__ == other.__origin__
1410 and self.__args__ == other.__args__)
1411
1412 def __hash__(self):
1413 return hash((self.__origin__, self.__args__))
1414
1415 def __or__(self, right):
1416 return Union[self, right]
1417
1418 def __ror__(self, left):
1419 return Union[left, self]
1420
1421 @_tp_cache
1422 def __getitem__(self, args):

Callers 10

ClassVarFunction · 0.85
FinalFunction · 0.85
TypeGuardFunction · 0.85
TypeFormFunction · 0.85
TypeIsFunction · 0.85
_generic_class_getitemFunction · 0.85
copy_withMethod · 0.85
RequiredFunction · 0.85
NotRequiredFunction · 0.85
ReadOnlyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…