I was looking at the source code of a Blender add-on and I saw a new syntax:
def elem_name_ensure_class(elem, clss=...):
elem_name, elem_class = elem_split_name_class(elem)
if clss is not ...:
assert(elem_class == clss)
return elem_name.decode('utf-8')
What is the meaning of ...
?
...
is a literal syntax for the Python Elipsis
object:
>>> ...
Ellipsis
It is mostly used by NumPy; see What does the Python Ellipsis object do?
The code you found uses it as a sentinel; a way to detect that a no other value was specified for the clss
keyword argument. Usually, you'd use None
for such a value, but that would disqualify None
itself from ever being used as a value.
Personally, I dislike using Ellipsis
as a sentinel; I would always create a dedicated sentinel instead:
_sentinel = object()
def elem_name_ensure_class(elem, clss=_sentinel):
elem_name, elem_class = elem_split_name_class(elem)
if clss is not _sentinel:
assert(elem_class == clss)
return elem_name.decode('utf-8')
Using the ...
notation outside of a subscription (object[...]
) is a syntax error in Python 2, so the trick used limits the code to Python 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With