(self, args)
| 1450 | return r |
| 1451 | |
| 1452 | def _determine_new_args(self, args): |
| 1453 | # Determines new __args__ for __getitem__. |
| 1454 | # |
| 1455 | # For example, suppose we had: |
| 1456 | # T1 = TypeVar('T1') |
| 1457 | # T2 = TypeVar('T2') |
| 1458 | # class A(Generic[T1, T2]): pass |
| 1459 | # T3 = TypeVar('T3') |
| 1460 | # B = A[int, T3] |
| 1461 | # C = B[str] |
| 1462 | # `B.__args__` is `(int, T3)`, so `C.__args__` should be `(int, str)`. |
| 1463 | # Unfortunately, this is harder than it looks, because if `T3` is |
| 1464 | # anything more exotic than a plain `TypeVar`, we need to consider |
| 1465 | # edge cases. |
| 1466 | |
| 1467 | params = self.__parameters__ |
| 1468 | # In the example above, this would be {T3: str} |
| 1469 | for param in params: |
| 1470 | prepare = getattr(param, '__typing_prepare_subst__', None) |
| 1471 | if prepare is not None: |
| 1472 | args = prepare(self, args) |
| 1473 | alen = len(args) |
| 1474 | plen = len(params) |
| 1475 | if alen != plen: |
| 1476 | raise TypeError(f"Too {'many' if alen > plen else 'few'} arguments for {self};" |
| 1477 | f" actual {alen}, expected {plen}") |
| 1478 | new_arg_by_param = dict(zip(params, args)) |
| 1479 | return tuple(self._make_substitution(self.__args__, new_arg_by_param)) |
| 1480 | |
| 1481 | def _make_substitution(self, args, new_arg_by_param): |
| 1482 | """Create a list of new type arguments.""" |
no test coverage detected