Merge "Remove usage of locals() for formatting from nova.api.*"

This commit is contained in:
Jenkins 2013-05-17 21:16:08 +00:00 committed by Gerrit Code Review
commit 156a2c26b8
2 changed files with 9 additions and 12 deletions

View File

@ -37,13 +37,13 @@ def process_todo_nodes(app, doctree, fromdocname):
for todo_info in env.todo_all_todos: for todo_info in env.todo_all_todos:
para = nodes.paragraph() para = nodes.paragraph()
filename = env.doc2path(todo_info['docname'], base=None)
# Create a reference # Create a reference
newnode = nodes.reference('', '') newnode = nodes.reference('', '')
line_info = todo_info['lineno'] filename = env.doc2path(todo_info['docname'], base=None)
link = _('%(filename)s, line %(line_info)d') % locals() link = (_('%(filename)s, line %(line_info)d') %
{'filename': filename, 'line_info': todo_info['lineno']})
innernode = nodes.emphasis(link, link) innernode = nodes.emphasis(link, link)
newnode['refdocname'] = todo_info['docname'] newnode['refdocname'] = todo_info['docname']

View File

@ -9,14 +9,11 @@ in a ``_()`` function call. For example::
LOG.debug(_("block_device_mapping %s"), block_device_mapping) LOG.debug(_("block_device_mapping %s"), block_device_mapping)
If you have multiple arguments, the convention is to use named parameters. Do not use ``locals()`` for formatting messages because:
It's common to use the ``locals()`` dict (which contains the names and values 1. It is not as clear as using explicit dicts.
of the local variables in the current scope) to do the string interpolation. 2. It could produce hidden errors during refactoring.
For example:: 3. Changing the name of a variable causes a change in the message.
4. It creates a lot of otherwise unused variables.
label = ...
sr_ref = ...
LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
If you do not follow the project conventions, your code may cause the If you do not follow the project conventions, your code may cause the
LocalizationTestCase.test_multiple_positional_format_placeholders test to fail LocalizationTestCase.test_multiple_positional_format_placeholders test to fail