Re: Supporting attribute-like properties



It would depend on the GObject sub-class whether a conflict would arise. I'm fairly new to python GObject programming and can only assume "props" was used to avoid potential conflicts or avoid cluttering up the objects dictionary which can be rather large with Gtk widgets. Personally I think a direct accessor would be nicer. However, if __getattr__ were used and there was a naming conflict, it might be awfully confusing figuring out what was going on and could contribute to extra support for maintainers when people run into it (trying to access a property with the same name as a method and getting a bound method as a result instead of a value might then be logged as a bug). A brief analysis reveals there would be a few conflicts in Gtk:

import inspect
from gi.repository import GObject, Gtk
for name in dir(Gtk):
    try:
        obj = getattr(Gtk, name)
    except:
        continue
    if inspect.isclass(obj) and issubclass(obj, GObject.GObject):
        intersection = set(dir(obj)).intersection(p for p in dir(obj.props) if not p.startswith('__'))
        if intersection:
            print name, intersection

-Simon

On Sat, May 26, 2012 at 12:14 AM, Kerrick Staley <mail kerrickstaley com> wrote:

Simon,
Thanks for the information about the props accessor; I'll certainly use it from here on.

Would there be any naming conflict if the GObject properties were directly available as objects' attributes, even for introspected libraries?

- Kerrick


_______________________________________________
python-hackers-list mailing list
python-hackers-list gnome org
https://mail.gnome.org/mailman/listinfo/python-hackers-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]