[prev in list] [next in list] [prev in thread] [next in thread]
List: trac
Subject: [Trac] Re: Confused about "PathOption" in a plugin/macro
From: Noah Kantrowitz <noah () coderanger ! net>
Date: 2009-10-31 3:38:31
Message-ID: 4B1FF2A6-233B-4090-A2D1-5D54BC5DD7B6 () coderanger ! net
[Download RAW message or body]
On Oct 30, 2009, at 2:01 PM, David Chase wrote:
>
>
> On 2009-10-30, at 4:42 PM, Noah Kantrowitz wrote:
>
>> The *Option classes are accessors, you use them in the context of
>> the class
>> definition like this:
>>
>> class Blah(Component):
>> latex_path = PathOption('fss', etc etc)
>>
>> def my_plugin_function(self, req):
>> print self.latex_path
>
> Thanks, but that's not actually helping me (and fortunately, I
> figured out another way to make this work, but from the POV of did you
> explain this in terms that a new-to-Python person could make sense of,
> I'm afraid you didn't).
>
> Is there something special about class definition context?
>
> Why would printing "self.latex_path" yield the desired string, instead
> of <Pathoption ... > like you get from "str"?
>
> This looks like the same sort of thing I was doing -- treating it as
> if it were a String -- but you get a different result. How? Why?
Yes, when you access it through self (through an object) you get the
value from the config. If you access it via the class
(Blah.latex_path) you get the PathOption object. Its a bit of magic in
how Python does attribute lookups, it ends up invoking code within the
PathOption object which ends up returning the config value. You should
definitely use the *Option classes in favor of the direct self.config
access so you get the auto-magic stuff in the IniAdmin plugin (and
anything else that introspects those, like the TracIni macro).
--Noah
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to trac-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic