3

Consider:

class MyCleanUpError(Exception):
    """Error raised during teardown."""
    pass

versus:

class MyCleanUpError(Exception):
    """Error raised during teardown."""

I've seen the class declared with and with out the pass statement. Which is appropriate?

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Nelly
  • 153
  • 9

1 Answers1

2

the pass statement simply does nothing. since """whatever this string is""" is a valid object, it is fine without the pass statement. you can also use ... (Ellipsis) in python 3 +, or 1, or None or whatever you want to do. you just cant do this:

class MyCleanUpError(Exception):

# other code

or else you will get an IndentationError. you also cant use a comment as a placeholder. it is generally appropriate to use pass or ..., because they make more sense than 1 or just having a docstring.

Michael
  • 436
  • 3
  • 11