This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [Python] Allow attribute references to gdb.Value objects
That's a fair point, but it comes at the expense of making the code look rather un-Pythonic. It seems reasonable to offer the option, and document the fact that code that takes advantage of it may be affected by new built-in attributes.
paul
-----Original Message-----
From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-owner@sourceware.org] On Behalf Of Tom Tromey
Sent: Monday, August 15, 2011 3:10 PM
To: Paul Koning
Cc: gdb-patches@sourceware.org
Subject: Re: [Python] Allow attribute references to gdb.Value objects
>>>>> "Paul" == Paul Koning <paulkoning@comcast.net> writes:
Paul> It would be more natural to be able to reference fields of a
Paul> gdb.Value by the standard field (attribute) syntax, e.g.,
Paul> "val1.field2" as opposed to "val1['field2']". The attached patch
Paul> does this. It acts like the Python standard method __getattr__ in
Paul> that it first looks for a predefined attribute (such as "type"),
Paul> and only if that fails will it look for a value field with the
Paul> given name. So val1.type means what it always did (and if you
Paul> want the "type" field of some structure value, you'd need to use
Paul> val1['type'] as before).
We considered this initially, but decided on the current approach instead. The current approach lets us add attributes to Value without breaking any existing code.
Tom