如何表达一个没有参数的Python调用?

2024-10-01 17:35:49 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python typing包的文档中,says

It is possible to declare the return type of a callable without specifying the call signature by substituting a literal ellipsis for the list of arguments in the type hint: Callable[..., ReturnType].

另一方面,它also says

Callable[..., ReturnType] (literal ellipsis) can be used to type hint a callable taking any number of arguments and returning ReturnType.

我想表达一个不带参数但返回字符串的函数。省略号似乎表示存在一些未指定的参数。我想表达的是,绝对没有争论。在

在我的类型提示中使用Callable[..., str]还有其他选择吗?在


Tags: oftheto文档typing参数typearguments

热门问题