Я пытаюсь повторно использовать подсказки типа из класса данных в сигнатуре моей функции, то есть без необходимости повторно вводить сигнатуру.
Как лучше всего поступить об этом?
from dataclasses import dataclass
from typing import Set, Tuple, Type
@dataclass
class MyDataClass:
force: Set[Tuple[str, float, bool]]
# I've had to write the same type annotation in the dataclass and the
# function signature - yuck
def do_something(force: Set[Tuple[str, float, bool]]):
print(force)
# I want to do something like this, where I reference the type annotation from
# the dataclass. But, doing it this way, pycharm thinks `force` is type `Any`
def do_something_2(force: Type["MyDataClass.force"]):
print(force)
Подробнее здесь: https://stackoverflow.com/questions/666 ... type-hints