Re: Supporting attribute-like properties
- From: Simon Feltman <s feltman gmail com>
- To: Kerrick Staley <mail kerrickstaley com>
- Cc: "python-hackers-list gnome org" <python-hackers-list gnome org>
- Subject: Re: Supporting attribute-like properties
- Date: Sat, 26 May 2012 01:24:04 -0700
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]