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

Method __getitem__

Lib/typing.py:1553–1574  ·  view source on GitHub ↗
(self, params)

Source from the content-addressed store, hash-verified

1551
1552 @_tp_cache
1553 def __getitem__(self, params):
1554 if not isinstance(params, tuple):
1555 params = (params,)
1556 msg = "Parameters to generic types must be types."
1557 params = tuple(_type_check(p, msg) for p in params)
1558 if (self._defaults
1559 and len(params) < self._nparams
1560 and len(params) + len(self._defaults) >= self._nparams
1561 ):
1562 params = (*params, *self._defaults[len(params) - self._nparams:])
1563 actual_len = len(params)
1564
1565 if actual_len != self._nparams:
1566 if self._defaults:
1567 expected = f"at least {self._nparams - len(self._defaults)}"
1568 else:
1569 expected = str(self._nparams)
1570 if not self._nparams:
1571 raise TypeError(f"{self} is not a generic class")
1572 raise TypeError(f"Too {'many' if actual_len > self._nparams else 'few'} arguments for {self};"
1573 f" actual {actual_len}, expected {expected}")
1574 return self.copy_with(params)
1575
1576 def copy_with(self, params):
1577 return _GenericAlias(self.__origin__, params,

Callers

nothing calls this directly

Calls 5

copy_withMethod · 0.95
isinstanceFunction · 0.85
_type_checkFunction · 0.85
lenFunction · 0.85
strFunction · 0.85

Tested by

no test coverage detected