How do you express a Python Callable with no arguments?


In the docs for the Python typing package, it 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].

On the other hand, it also says:

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

I want to express a function that takes no arguments but returns a string. The ellipsis seems to indicate that there are some unspecified arguments. I want to express that that there definately are zero arguements.

Do I have any alternatives to using Callable[..., str] in my type hint?

Asked By: kingledion



It requires a sequence of argument types, so if there are no types, you pass it an empty sequence:

Callable[[], str]
Answered By: juanpa.arrivillaga
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.