Reputation: 71
This is the code of the atan
and tan
functions in the math
module in Python. Their body consist of three dots (...
). Many built-in functions also do the same. What is the meaning of that and where can I see the full body instead of three dots?
def tan(__x: _SupportsFloatOrIndex) ->float: ...
def atan(__x: _SupportsFloatOrIndex) ->float: ...
Upvotes: 5
Views: 5179
Reputation: 462
It seems you dug into the math
library.
Actually, the file you are referencing is a Python module written in C.
In order to add type-hints to that file (which is an "Extension Module" as it is written in C), the type hints are added to a "stub" file with the extension .pyi
.
Here the ellipsis (...
) is part of the syntax, so the code-block below really shows the complete file contents.
Here is a detailed explanation: What is the use of stub files (.pyi ) in python?
Upvotes: 8
Reputation: 2190
It's the Ellipsis. It has many meanings and none at all. Let me explain:
It's an 'empty' singleton object with no methods, and its interpretation is purely up to context.
pass
or not yet implemented code:
def my_function(arg):
...
def partial(func: Callable[..., str], *args) -> Callable[..., str]:
# code
>>> import numpy as np
>>> array = np.random.rand(2, 2, 2, 2)
>>> print(array[..., 0])
[[[0.03265588 0.85912865]
[0.45491733 0.3654667 ]]
[[0.58577745 0.11642329]
[0.88552571 0.69755581]]]
Upvotes: 11