MCPcopy Index your code
hub / github.com/RustPython/RustPython / _GenericAlias

Class _GenericAlias

Lib/typing.py:1315–1533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1313
1314
1315class _GenericAlias(_BaseGenericAlias, _root=True):
1316 # The type of parameterized generics.
1317 #
1318 # That is, for example, `type(List[int])` is `_GenericAlias`.
1319 #
1320 # Objects which are instances of this class include:
1321 # * Parameterized container types, e.g. `Tuple[int]`, `List[int]`.
1322 # * Note that native container types, e.g. `tuple`, `list`, use
1323 # `types.GenericAlias` instead.
1324 # * Parameterized classes:
1325 # class C[T]: pass
1326 # # C[int] is a _GenericAlias
1327 # * `Callable` aliases, generic `Callable` aliases, and
1328 # parameterized `Callable` aliases:
1329 # T = TypeVar('T')
1330 # # _CallableGenericAlias inherits from _GenericAlias.
1331 # A = Callable[[], None] # _CallableGenericAlias
1332 # B = Callable[[T], None] # _CallableGenericAlias
1333 # C = B[int] # _CallableGenericAlias
1334 # * Parameterized `Final`, `ClassVar`, `TypeGuard`, and `TypeIs`:
1335 # # All _GenericAlias
1336 # Final[int]
1337 # ClassVar[float]
1338 # TypeGuard[bool]
1339 # TypeIs[range]
1340
1341 def __init__(self, origin, args, *, inst=True, name=None):
1342 super().__init__(origin, inst=inst, name=name)
1343 if not isinstance(args, tuple):
1344 args = (args,)
1345 self.__args__ = tuple(... if a is _TypingEllipsis else
1346 a for a in args)
1347 enforce_default_ordering = origin in (Generic, Protocol)
1348 self.__parameters__ = _collect_type_parameters(
1349 args,
1350 enforce_default_ordering=enforce_default_ordering,
1351 )
1352 if not name:
1353 self.__module__ = origin.__module__
1354
1355 def __eq__(self, other):
1356 if not isinstance(other, _GenericAlias):
1357 return NotImplemented
1358 return (self.__origin__ == other.__origin__
1359 and self.__args__ == other.__args__)
1360
1361 def __hash__(self):
1362 return hash((self.__origin__, self.__args__))
1363
1364 def __or__(self, right):
1365 return Union[self, right]
1366
1367 def __ror__(self, left):
1368 return Union[left, self]
1369
1370 @_tp_cache
1371 def __getitem__(self, args):
1372 # Parameterizes an already-parameterized object.

Callers 9

ClassVarFunction · 0.85
FinalFunction · 0.85
TypeGuardFunction · 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