| 1363 | |
| 1364 | |
| 1365 | class _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): |
no outgoing calls
no test coverage detected
searching dependent graphs…