Message82705
I just took a quick look at Lib/abc.py 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)
True
>>> isinstance(f, IOBase)
True
>>> f = open('foobar', 'w')
>>> isinstance(f, IOBase)
True
>>> isinstance(f, TextIOBase)
True
>>> isinstance(f, RawIOBase)
False
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
closing
>>>
Perhaps we could even do all this in Python in io.py? |
|
Date |
User |
Action |
Args |
2009-02-25 15:15:04 | pitrou | set | recipients:
+ pitrou, rhettinger, gregory.p.smith, exarkun, amaury.forgeotdarc, giampaolo.rodola, christian.heimes, benjamin.peterson, wplappert, ialbert |
2009-02-25 15:15:04 | pitrou | set | messageid: <1235574904.03.0.830057342029.issue4565@psf.upfronthosting.co.za> |
2009-02-25 15:15:01 | pitrou | link | issue4565 messages |
2009-02-25 15:15:00 | pitrou | create | |
|