Reputation: 314
How can I specify a type hint for a function that expects a literal Ellipsis
(or ...
) as an argument? In analogy with None
, I'm tempted to write something like:
def f(x: Ellipsis):
return
f(Ellipsis)
If I run this through mypy
, however, I get:
1: error: Variable "builtins.Ellipsis" is not valid as a type
mypy
is happy with the following:
import builtins
def f(x: builtins.ellipsis):
return
f(Ellipsis)
But this fails at runtime with:
AttributeError: module 'builtins' has no attribute 'ellipsis'.
Upvotes: 8
Views: 3954