Код: Выделить всё
T = TypeVar('T')
CustomUrl = Annotated[str, T]
Код: Выделить всё
CustomUrl[MyData()]
# TypeError: typing.Annotated[str, ~T] is not a generic class
Код: Выделить всё
CustomUrl[T, str]
Мой вариант использования — попросить пользователя объявить класс данных, и он автоматически сгенерирует схему пользовательского интерфейса, например
< pre class="lang-py Prettyprint-override">
Код: Выделить всё
# pseudo code
@dataclass
class TaskArgs:
input_text: Annotated[str, {'multiline': True}]
input_file: Annotated[str, {'multifiles': True}]
Я попробовал следующий ответ:
Код: Выделить всё
from typing import Annotated, TypeVar
T = TypeVar('T')
class CustomeUrl(Annotated[str, T]):
...
c: CustomeUrl = 's'
Код: Выделить всё
Expression of type "Literal['s']" is incompatible with declared type "CustomeUrl"
"Literal['s']" is incompatible with "CustomeUrl"
Подробнее здесь: https://stackoverflow.com/questions/784 ... works-well