Код: Выделить всё
from typing import Protocol, TypeVar, Any
type _KeyT[T] = type[T]
T = TypeVar('T', bound='SomeClass')
class Store(Protocol):
def __getitem__(self, __key: _KeyT[T]) -> T: ...
def __delitem__(self, __key: _KeyT[T]) -> None: ...
def __setitem__(self, __key: _KeyT[T], __value: T) -> None: ...
def get(self, key: _KeyT[T], default: None = None) -> Any | None: ...
Код: Выделить всё
from typing import cast
a: Store = cast(Store, {})
Есть ли способ добавить подсказки типов также для Store.values/
Код: Выделить всё
.keys/.itemsЯ пробовал использовать это:
Код: Выделить всё
from _collections_abc import dict_items, dict_keys, dict_values
Для чего-то вроде defvalues(self) -> list[T] я не уверен, что list является полной заменой dict_values.>
Подробнее здесь: https://stackoverflow.com/questions/798 ... -in-python
Мобильная версия