Im Wesentlichen möchte ich, dass meine Funktionssignatur so aussieht:
Code: Select all
def foo[*Cs](*classes: type[*Cs]) -> tuple[*Cs]:
return tuple(cls() for cls in classes)
Code: Select all
TypeVarTuple
Die Funktion sollte eine beliebige Anzahl von Klassen als Funktionsargumente akzeptieren und ein Tupel von Instanzen zurückgeben, deren Elementtypen positionell den Eingabeargumenten entsprechen. Die statischen Rückgabetypen sollten wie folgt aussehen:
Code: Select all
foo(int, int, str) -> tuple[int, int str]
Code: Select all
foo(str, str, str)
# > foo(, , ) -> [, , ]
Code: Select all
def bar[T](cls: type[T]) -> T:
return cls()
Code: Select all
_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
Mobile version