In type hinting
Ellipsis is used in specifying type hints using the typing module (e.g. Callable[…, str]). It can serve in either way:
When the argument(s) of the function allows the type: Any
Actually callable takes the arguments:
Callable "[" parameters_expression, type_expression "]"
(e.g. Callable[…, str])
Example:
Python3
from typing import Callable def inject(get_next_item: Callable [..., str ]) - > None : ... # Argument type is assumed as type: Any def foo(x: ...) - > None : ... |
Using ‘…’ as parameters_expression signifies a function that returns a string without specifying the call signature.
When the return value of the function is of type: Any
Actually callable returns this way:
Callable "[" parameters_expression, type_expression "]" -> return_type: #body
Example:
Python3
class flow: # (using "value: Any" to allow arbitrary types) def __understand__( self , name: str , value: ...) - > None : ... |
What is Three dots(…) or Ellipsis in Python3
Ellipsis is a Python Object. It has no Methods. It is a singleton Object i.e. , provides easy access to single instances.
Various Use Cases of Ellipsis (…):
- Default Secondary Prompt in Python interpreter.
- Accessing and slicing multidimensional Arrays/NumPy indexing.
- In type hinting.
- Used as Pass Statement inside Functions.