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

Method _determine_new_args

Lib/typing.py:1401–1428  ·  view source on GitHub ↗
(self, args)

Source from the content-addressed store, hash-verified

1399 return r
1400
1401 def _determine_new_args(self, args):
1402 # Determines new __args__ for __getitem__.
1403 #
1404 # For example, suppose we had:
1405 # T1 = TypeVar('T1')
1406 # T2 = TypeVar('T2')
1407 # class A(Generic[T1, T2]): pass
1408 # T3 = TypeVar('T3')
1409 # B = A[int, T3]
1410 # C = B[str]
1411 # `B.__args__` is `(int, T3)`, so `C.__args__` should be `(int, str)`.
1412 # Unfortunately, this is harder than it looks, because if `T3` is
1413 # anything more exotic than a plain `TypeVar`, we need to consider
1414 # edge cases.
1415
1416 params = self.__parameters__
1417 # In the example above, this would be {T3: str}
1418 for param in params:
1419 prepare = getattr(param, '__typing_prepare_subst__', None)
1420 if prepare is not None:
1421 args = prepare(self, args)
1422 alen = len(args)
1423 plen = len(params)
1424 if alen != plen:
1425 raise TypeError(f"Too {'many' if alen > plen else 'few'} arguments for {self};"
1426 f" actual {alen}, expected {plen}")
1427 new_arg_by_param = dict(zip(params, args))
1428 return tuple(self._make_substitution(self.__args__, new_arg_by_param))
1429
1430 def _make_substitution(self, args, new_arg_by_param):
1431 """Create a list of new type arguments."""

Callers 1

__getitem__Method · 0.95

Calls 4

_make_substitutionMethod · 0.95
getattrFunction · 0.85
prepareFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected