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

Terry Reedy tjreedy at udel.edu
Tue Sep 4 19:16:41 EDT 2012


On 9/4/2012 6:18 PM, Chris Angelico wrote:
> On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy <tjreedy at udel.edu> wrote:
>> io.open depends on a function the returns an open file descriptor. opener
>> exposes that dependency so it can be replaced.
>
> I skimmed the bug report comments but didn't find an answer to this:
> Why not just monkey-patch?

As far as I know, one can only use normal Python code to monkey patch 
modules written in Python. Even then, one can only rebind names stored 
in writable dicts -- the module dict and class attribute dicts. The 
attributes of function code objects are readonly. Replacing a code 
object is not for the faint of heart.

io.py mostly loads _io compiled from C.


-- 
Terry Jan Reedy




More information about the Python-list mailing list