Instances behaviour
Inyeol Lee
inyeol.lee at siliconimage.com
Fri Dec 2 14:23:45 EST 2005
On Fri, Dec 02, 2005 at 10:43:56AM +0100, bruno at modulix wrote:
> Inyeol Lee wrote:
> (snip)
>
> >>>>class A(object):
> >>>>... def __init__(self, foo):
> >>>>... if self.__class__ is A:
> >>>>... raise TypeError("A is base class.")
>
>
> s/TypeError/NotImplementedError/
> s/base class/abstract class/
I prefer TypeError here, NotImplementedError would be OK though.
Here is an example from sets.py in stdlib.
class BaseSet(object):
"""Common base class for mutable and immutable sets."""
__slots__ = ['_data']
# Constructor
def __init__(self):
"""This is an abstract class."""
# Don't call this from a concrete subclass!
if self.__class__ is BaseSet:
raise TypeError, ("BaseSet is an abstract class. "
"Use Set or ImmutableSet.")
Inyeol
More information about the Python-list
mailing list