PEP 3119 ABC - And how I learned to love the Abstract Bomb

Hatem Nassrat hnassrat at gmail.com
Wed May 12 00:38:47 EDT 2010


Today I was doing a major re-write of a library I called yajl-py that
wraps the json 'sax-like' c-parser yajl, and decided I should look
into absract base classes since I knew they had been added to py26.
Truthfully, I was surprised when I found out that the BDFL accepted
this PEP, but hey were in 2010 :p.

So I was getting around to using it when I realised that I cannot make
my class as abstract as can be. Here is my dilemma / requirements:

1. To create a YajlContentHandler class that forces all sub-classers
to implement a certain set of methods. (Great, thats what ABC is for)

There is a certain set of mutually exclusive callbacks, i.e. if you
implement the first set you need not implement the second, and vice
versa, so my second requirement is:

2. Conditional Abstractness! if certain methods are not implemented
then be able to require some method to be implemented.

Python is more flexible than Java, so having Conditional Meta Abstract
Base Classes seems only natural :P, maybe someone should write a PEP.
This only reminds me of the following tweet:
http://twitter.com/bos31337/status/13349058839

--
Hatem Nassrat



More information about the Python-list mailing list