По сути, я хочу, чтобы моя сигнатура функции была именно такой:
Код: Выделить всё
def foo[*Cs](*classes: type[*Cs]) -> tuple[*Cs]:
return tuple(cls() for cls in classes)
Код: Выделить всё
TypeVarTuple
Функция должна принимать любое количество классов в качестве аргументов функции и возвращает кортеж экземпляров, типы элементов которых позиционно соответствуют входным аргументам. Статические типы возвращаемых данных должны выглядеть следующим образом:
Код: Выделить всё
foo(int, int, str) -> tuple[int, int str]
Код: Выделить всё
foo(str, str, str)
# > foo(, , ) -> [, , ]
Код: Выделить всё
def bar[T](cls: type[T]) -> T:
return cls()
Код: Выделить всё
_C = _TypeVar('_C')
_C2 = _TypeVar('_C2')
_C3 = _TypeVar('_C3')
_C4 = _TypeVar('_C4')
@_overload
def get_components(__c1: _Type[_C], __c2: _Type[_C2]) -> _List[_Tuple[int, _Tuple[_C, _C2]]]:
...
@_overload
def get_components(__c1: _Type[_C], __c2: _Type[_C2], __c3: _Type[_C3]) -> _List[_Tuple[int, _Tuple[_C, _C2, _C3]]]:
...
@_overload
def get_components(__c1: _Type[_C], __c2: _Type[_C2], __c3: _Type[_C3], __c4: _Type[_C4]) -> _List[
_Tuple[int, _Tuple[_C, _C2, _C3, _C4]]]:
...
def get_components(*component_types: _Type[_Any]) -> _List[_Tuple[int, _Tuple[_Any, ...]]]:
"""Get an iterator for Entity and multiple Component sets."""
if _cache_dirty:
_clear_cache_now()
cached = _get_components_cache.get(component_types)
if cached is not None:
return cached
result = list(_get_components(*component_types))
_get_components_cache[component_types] = result
return result
Подробнее здесь: https://stackoverflow.com/questions/798 ... equivalent
Мобильная версия