[Texas] Python koans: about_proxy_object_project.py now I know what lost feels like

Alex Robbins alexander.j.robbins at gmail.com
Wed Sep 8 19:06:58 CEST 2010


Mark,

Sorry about the lag on a reply. Life is busy and all that...

So, this koan is actually related to the last one you had a question
about, with __setattr__. We want all calls to the proxy object to be
passed along to the target_object. We also want to build up a list of
all the attributes that were accessed.

I think you were on the right track with the __getattr__ method. (Some
docs for __getattr__:
http://docs.python.org/release/2.5.2/ref/attribute-access.html ) With
__getattr__ we can intercept calls to any method/attribute without
hardcoding them all beforehand. You shouldn't need to add any of those
other methods to your proxy object, just the __getattr__. I think
maybe your @property'ed channel function is getting in the way.

Really, the proxy object should just have the __getattr__ method to
pass attribute lookups along, and then a messages method to display
the list.

Does that fix it for you? I haven't actually run it locally, so I
can't guarantee my explanation actually works.

Alex



On Sat, Sep 4, 2010 at 9:58 PM, Mark Sharp <msharp at sfbr.org> wrote:
> I thought I was keeping up until I hit about_proxy_object_project.py. I got four tests to pass out of pure guess work, but I do not know what I am doing.
>
> Here is where I am.
>
>  test_proxy_can_record_more_than_just_tv_objects has expanded your awareness.
>  test_proxy_handles_invalid_messages has expanded your awareness.
>  test_proxy_method_returns_wrapped_object has expanded your awareness.
>  test_tv_methods_still_perform_their_function has expanded your awareness.
>  test_proxy_records_messages_sent_to_tv has damaged your karma.
>
> You have not yet reached enlightenment ...
>  AssertionError: Lists differ: ['power', 'channel='] != ['power']
>
>  First list contains 1 additional elements.
>  First extra element 1:
>  channel=
>
>  - ['power', 'channel=']
>  + ['power']
>
> I am currently trying to figure out how to record that the channel property was set. I do not know how to track it through the Proxy class using pdb. I put the following code in the Proxy class, but I do not think it is even touched (nor do I have any reason to believe it would work if it were accessed).
>
>    @property
>    def channel(self):
>        self._messages.append('channel')
>        return self._obj.channel
>    def channel(self, value):
>        if self._obj.channel:
>            self._messages.append('channel =')
>            self._obj.channel.setter(self._obj, value)
>
> Any guidance would be appreciated.
>
> I have attached my messed up version of about_proxy_object_project.py
>
> Mark Sharp
>
>
> _______________________________________________
> Texas mailing list
> Texas at python.org
> http://mail.python.org/mailman/listinfo/texas
>
>


More information about the Texas mailing list