Search code examples
pythonpython-typingellipsis

python: annotation for ellipsis to be a possible argument of a function


For "certain reasons" I want to allow python's Ellipsis "..." to (also) be an argument to some function (let's say) f, e.g. as follows:

def f(arg: ?) -> None:
    print(arg)

f(...)

what annotation should I use for arg?


Solution

  • It appears (see python doc: https://docs.python.org/3/library/constants.html#Ellipsis) that

    from types import EllipsisType
    
    def f(arg: EllipsisType):
        print(arg)
    
    f(...)  # or alternatively f(Ellipsis)
    

    is the right solution here (i.e. to annotate the Ellipsis itself)