The opener parameter of Python 3 open() built-in

Terry Reedy tjreedy at udel.edu
Tue Sep 4 15:16:38 EDT 2012


On 9/4/2012 8:58 AM, Serhiy Storchaka wrote:
> On 04.09.12 04:13, Steven D'Aprano wrote:
>> Why does the open builtin need this added complexity? Why not just call
>> os.open directly? Or for more complex openers, just call the opener
>> directly?
>>
>> What is the rationale for complicating open instead of telling people to
>> just call their opener directly?
>
> See http://bugs.python.org/issue12797.

io.open depends on a function the returns an open file descriptor. 
opener exposes that dependency so it can be replaced. (Obviously, one 
could go crazily overboard with this idea.) I believe this is a simple 
form of dependency injection, though it might be hard to discern from 
the Java-inspired verbiage of the Wikipedia article. Part of the 
rationale in the issue is to future-proof io.open from any future needs 
for alternate fd fetching. It could also be used to decouple a test of 
io.open from os.open

-- 
Terry Jan Reedy




More information about the Python-list mailing list