Author pitrou
Recipients amaury.forgeotdarc, benjamin.peterson, christian.heimes, exarkun, giampaolo.rodola, gregory.p.smith, ialbert, pitrou, rhettinger, wplappert
Date 2009-02-25.15:14:59
SpamBayes Score 8.76521e-14
Marked as misclassified No
Message-id <>
I just took a quick look at Lib/ and there's no way *I*'ll
reimplement it in C :)

The only workable approach would be:
1. rename the current would-be ABCs (IOBase, RawIOBase, etc.) with a
leading underscore (_IOBase, _RawIOBase, etc.)
2. call abc.ABCMeta() with the right arguments to create heap-types 
derived from those base types
3. call XXXIOBase.register() with each of the concrete classes
(BufferedReader, etc.) to register them with the ABCs created in 2

That is, do something like the following:

>>> IOBase = abc.ABCMeta("IOBase", (_io.IOBase,), {})
>>> RawIOBase = type("RawIOBase", (_io.RawIOBase, IOBase), {})
>>> RawIOBase.register(_io.FileIO)
>>> TextIOBase = type("TextIOBase", (_io.TextIOBase, IOBase), {})
>>> TextIOBase.register(_io.TextIOWrapper)

Which gives:
>>> f = open('foobar', 'wb', buffering=0)
>>> isinstance(f, RawIOBase)
>>> isinstance(f, IOBase)
>>> f = open('foobar', 'w')
>>> isinstance(f, IOBase)
>>> isinstance(f, TextIOBase)
>>> isinstance(f, RawIOBase)

As you see, RawIOBase inherits both from IOBase (the ABC, for ABC-ness)
and _RawIOBase (the concrete non-ABC implementation). Implementation
classes like FileIO don't need to explicitly inherit the ABCs, only to
register with them.

Also, writing a Python implementation still inherits the
close-on-destroy behaviour:

>>> class S(RawIOBase):
...   def close(self):
...     print("closing")
>>> s = S()
>>> del s

Perhaps we could even do all this in Python in
Date User Action Args
2009-02-25 15:15:04pitrousetrecipients: + pitrou, rhettinger, gregory.p.smith, exarkun, amaury.forgeotdarc, giampaolo.rodola, christian.heimes, benjamin.peterson, wplappert, ialbert
2009-02-25 15:15:04pitrousetmessageid: <>
2009-02-25 15:15:01pitroulinkissue4565 messages
2009-02-25 15:15:00pitroucreate