idioms for abstract base classes

Rainer Deyke root at rainerdeyke.com
Fri Apr 13 17:45:53 EDT 2001


"Ben Wolfson" <wolfson at uchicago.edu> wrote in message
news:yvHB6.142$E4.6764 at uchinews...
> In article <mailman.987183619.7370.python-list at python.org>, "Carlos
> Ribeiro" <cribeiro at mail.inet.com.br> wrote:
>
> > In Delphi, there is a "abstract" keyword that can be used as syntactic
> > sugar as in the example below:
> >
> > class B:
> >    def __init__(self): abstract
> >    def dosomething(self): abstract
> >
> > ...where "abstract" will raise a "abstract method exception". Do anyone
> > smells a PEP here <wink>?
>
> You can already do:
>
> class B:
>    def __init__(self): raise NotImplementedError
>    def dosomething(self): raise NotImplementedError
>
> or even:
>
> def _abstract(): raise NotImplementedError
> class B:
>    def __init__(self): _abstract()

Or even:

def abstract(self, *args, **kwargs): raise NotImplementedError
class B:
  __init__ = abstract
  dosomething = abstract


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list