When is the usage of the Python Ellipsis to be preferred over ‘pass’?

Using the Ellipsis literal as the body of a function does nothing. It’s purely a matter of style if you use it instead of pass or some other statement. If you give your function a docstring, you don’t even need to put any statement after the line with the docstring.

If the official Python documentation is inconsistent, it’s probably because the Python core developers who write the docs don’t themselves have a consistent opinion on which looks best. PEP 8 does not give any recommendation on what to use for the body of dummy functions (though it does use lots of ...s to stand in for things in its examples, sometimes in places where you can’t actually use an Ellipsis in real code).

So for your own code, use whatever you like best. If you want to be formal about it, write down your preferences in your style guide and then always do whatever the guide says. You don’t need to follow the same style as anyone else (unless that person is your boss).

One final note: You can’t use ... as a parameter name in a function definition (def my_abstract_method(self, ...): raises a SyntaxError, regardless of what’s on the next line).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)