[Python-Dev] Shared ABCs for the IO implementation
Guido van Rossum
guido at python.org
Wed Feb 25 18:29:56 CET 2009
On Wed, Feb 25, 2009 at 7:35 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> I would like to know if both IO implementations (the C one and the Python one)
> should share their ABCs (IOBase, RawIOBase, etc.). It looks preferable to me but
> since I'm not very familiar with ABCs I'd like to be sure it's the good choice.
>
> (of course, the *implementations* won't be shared at all. Just the virtual
> inheritance information)
Without a shared ABC you'd defeat the whole point of having ABCs.
However, importing ABCs (which are defined in Python) from C code
(especially such fundamental C code as the I/O library) is really
subtle and best avoided.
In io.py I solved this by having a Python class inherit from both the
ABC (RawIOBase) and the implementation (_fileio._FileIO).
Another way to solve it would be to use the registration API for ABCs,
as found in _abcoll.py (e.g. MutableSequence.register(list)).
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list