MCPcopy Index your code
hub / github.com/python/cpython / __getitem__

Method __getitem__

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

Source from the content-addressed store, hash-verified

1602
1603 @_tp_cache
1604 def __getitem__(self, params):
1605 if not isinstance(params, tuple):
1606 params = (params,)
1607 msg = "Parameters to generic types must be types."
1608 params = tuple(_type_check(p, msg) for p in params)
1609 if (self._defaults
1610 and len(params) < self._nparams
1611 and len(params) + len(self._defaults) >= self._nparams
1612 ):
1613 params = (*params, *self._defaults[len(params) - self._nparams:])
1614 actual_len = len(params)
1615
1616 if actual_len != self._nparams:
1617 if self._defaults:
1618 expected = f"at least {self._nparams - len(self._defaults)}"
1619 else:
1620 expected = str(self._nparams)
1621 if not self._nparams:
1622 raise TypeError(f"{self} is not a generic class")
1623 raise TypeError(f"Too {'many' if actual_len > self._nparams else 'few'} arguments for {self};"
1624 f" actual {actual_len}, expected {expected}")
1625 return self.copy_with(params)
1626
1627 def copy_with(self, params):
1628 return _GenericAlias(self.__origin__, params,

Callers

nothing calls this directly

Calls 3

copy_withMethod · 0.95
_type_checkFunction · 0.85
strFunction · 0.85

Tested by

no test coverage detected