Subclassing by monkey-patching

Peter Otten __peter__ at web.de
Sun Sep 5 12:56:28 CEST 2010


Jason wrote:

> On Sep 5, 3:53 pm, Peter Otten <__pete... at web.de> wrote:
>> >>> m = gio.File(".").monitor_directory()
>> >>> C = type(m)
> 
> 'C' will not necessarily be 'gio.FileMonitor' — I think the internals
> of the GIO methods might further "subclass" it in some way depending
> on what underlying monitors are available.

That would only be relevant if it had worked, I think ;)
 
>> A possible alternative may be a class that wraps a FileMonitor instead of
>> subclassing it.
> 
> I've been avoiding this because it involves a lot of boilerplate: the
> signals needs to be replicated and passed through, same for all
> GObject properties, same for the usual methods. I'd basically have to
> re-write the entire class in Python, and then tack on my methods.
> Otherwise I have to write two sets of methods for anything that
> touches this wrapped object.
> 
> Still, if it's the only way, sure.

Does it have to be gio.FileMonitor? pyinotify can automatically add new 
subdirectories out of the box.

Peter



More information about the Python-list mailing list