[openstack-dev] Use of local()

Joshua Harlow harlowja at yahoo-inc.com
Fri Feb 8 02:42:42 UTC 2013


The issue I have with locals() is locality.

Now instead of easily seeing what variables (or where they came from) are
going to be used in a string just by looking at the same line you have to
start looking around the function scope or other scope to figure out what
is being used in said string for formatting, that means every time to
understand the string you have to scan the function, which is like 10
seconds of your life down the drain.

My 2 cents. I'd like to spend those 10 seconds doing other stuff :-P

On 2/7/13 12:30 PM, "Jay Pipes" <jaypipes at gmail.com> wrote:

>Yes, and I'm saying I prefer the use of locals() over manually
>specifying a dictionary.
>
>-jay
>
>On 02/07/2013 03:15 PM, Joe Gordon wrote:
>> i18n support prevents us from doing something like:
>> 
>> 
>> _("The server with id %()s has no key %s" % (s_id, m_key))
>> 
>> Because translations my reverse the sentence structures.  So the two
>> options are:
>> 
>> 
>> _("The server with id %(s_id)s has no key %(m_key)s" % locals())
>> 
>> and 
>> 
>> 
>> msg = _("The server with id %(s_id)s has no key %(m_key)s")
>> LOG.error(msg % {"s_id": "1234", "m_key": "imageId"})
>> 
>> 
>> 
>>https://github.com/openstack/nova/blob/master/HACKING.rst#internationaliz
>>ation-i18n-strings
>> 
>> On Thu, Feb 7, 2013 at 11:49 AM, Jay Pipes <jaypipes at gmail.com
>> <mailto:jaypipes at gmail.com>> wrote:
>> 
>>     I actually prefer the use of locals()... I find it cleaner that
>>     specifying huge dictionaries to supply for string interpolation.
>> 
>>     -jay
>> 
>>     On 02/07/2013 02:33 PM, Andrew Laski wrote:
>>     > On 02/07/13 at 10:23am, Nachi Ueno wrote:
>>     >> Hi folks
>>     >>
>>     >> I wanna ask the opinion of use of local()
>>     >> This function is mainly used for logging because of no need to
>>     specify
>>     >> actual parameters.
>>     >>
>>     >> However, the variable ,which code checker says it is not used, is
>>     used
>>     >> by local() sometimes.
>>     >> so I prefer not to use local() .
>>     >> I also believe to specify used parameter improves readability of
>>     the code.
>>     >
>>     > I agree.  I prefer the explicitness of passing variables to string
>>     > interpolation, and my style checker also picks up the variables
>>     which it
>>     > thinks are not used.
>>     >
>>     > I would support a check in hacking.py for this in Nova but
>>personally
>>     > don't think reviewers should spend time worrying about it.  Which
>>     means
>>     > that I think it's an uphill battle for projects without something
>>like
>>     > hacking.py.
>>     >
>>     >
>>     >>
>>     >> I appreciate if I could get the opinion on the community.
>>     >>
>>     >> Thanks
>>     >> Nachi
>>     >>
>>     >> _______________________________________________
>>     >> OpenStack-dev mailing list
>>     >> OpenStack-dev at lists.openstack.org
>>     <mailto:OpenStack-dev at lists.openstack.org>
>>     >> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>>     >
>>     > _______________________________________________
>>     > OpenStack-dev mailing list
>>     > OpenStack-dev at lists.openstack.org
>>     <mailto:OpenStack-dev at lists.openstack.org>
>>     > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>>     >
>> 
>>     _______________________________________________
>>     OpenStack-dev mailing list
>>     OpenStack-dev at lists.openstack.org
>>     <mailto:OpenStack-dev at lists.openstack.org>
>>     http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>> 
>> 
>> 
>> 
>> _______________________________________________
>> OpenStack-dev mailing list
>> OpenStack-dev at lists.openstack.org
>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>> 
>
>_______________________________________________
>OpenStack-dev mailing list
>OpenStack-dev at lists.openstack.org
>http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev




More information about the OpenStack-dev mailing list