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: ...
CodePudding user response:
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.
Type-hints are added via a stub-file *.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. https://stackify.dev/907320-what-is-the-use-of-stub-files-pyi-in-python
CodePudding user response:
It's the Ellipsis, it has many meanings and none at all. Let me explain;
It's an 'empty' singleton object with no method and its interpretation is purely up to whatever implements the __getitem__ function and sees Ellipsis objects there.
- It can be used as a substitute for
passor not yet implemented code;
def my_function(arg):
...
- It is used to denote certain types to a static type checker when using the typing module (for type hints).
def partial(func: Callable[..., str], *args) -> Callable[..., str]:
# code
- In slice syntax to represent the full slice in remaining dimensions;
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]]]
Thank you so much for this question, I learned something new in Python today.
