[Freeipa-devel] keys[-1] idiom?

John Dennis jdennis at redhat.com
Mon Jun 11 12:50:47 UTC 2012


On 06/10/2012 03:33 PM, Martin Kosek wrote:
> On Fri, 2012-06-08 at 10:56 -0400, John Dennis wrote:
>> I frequently see this idiom in the code in plugins and pre/post callbacks:
>>
>> keys[-1]
>>
>> My understanding is that keys in the positional parameter list of the
>> command, correct?
>
> Correct.
>
>>
>> keys always appears in a formal parameter list with the parameter
>> "options", which I believe are the keyword arguments of the command
>> (i.e. *args, **kwds)
>>
>> Thus keys[-1] would be the last positional parameter. What is special
>> about it such that one can always reference the last positional
>> parameter? (or have I misunderstood, if so please elucidate).
>
> I am a bit lost here. As you correctly stated, keys contains the
> positional parameters. Each keys value should uniquely point to one LDAP
> entry represented by LDAPObject class. We use keys[-1] for a case when
> LDAPObjects are nested and keys list holds more than one value and thus
> keys[0] would not work. For example keys list for DNS record could hold
> ('example.com', 'ipa').
>
>>
>> If keys is the positional parameter list (e.g. *args) why is is called
>> "keys"? That seems really confusing because keys usually has an entirely
>> different meaning (i.e. keys of a dict). Why isn't it named "args"?
>>
>
> Maybe Rob will know why we started calling it keys, I think it is not a
> total non-sense, after all it holds primary _key_ values for referred
> LDAPObjects...

Thanks Martin:

Your explanation seems to imply the position parameters for a command 
always reference a dn or rdn. Is that true? We don't use positional 
parameters for anything else?

However when I look through the code I see a lot of places where 
keys[-1] is used and that value does not appear to be interpreted as an 
LDAP entry or pointer to an LDAP entry (e.g. a dn)

John

(who is still confused and suspects there is some convention being used 
in our code he is not aware of).


-- 
John Dennis <jdennis at redhat.com>

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/




More information about the Freeipa-devel mailing list