[Python-Dev] OT: Performance vs. Clarity vs. Convention

Greg Ewing greg@cosc.canterbury.ac.nz
Fri, 07 Jun 2002 12:53:52 +1200 (NZST)


Guido van Rossum <guido@python.org>:

> > >     def __str__(self):
> > >         pass
> > 
> > Dunno about other people's opinions, but I have a strong distaste for
> > creating methods whose body contains pass.  I always use "raise
> > NotImplementedError".
> 
> But that has different semantics!

In this particular case, the program blows up anyway if this
method is ever called, so you might as well return a meaningful
exception!

Python 2.2 (#14, May 28 2002, 14:11:27) 
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> class C:
...  def __str__(self):
...   pass
... 
>>> c = C()
>>> str(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: __str__ returned non-string (type NoneType)
>>> 

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+