summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-05-17 21:16:08 +0000
committerGerrit Code Review <review@openstack.org>2013-05-17 21:16:08 +0000
commit55ccdbc3bc62dc32161112a77c0fed39e73ee7b4 (patch)
treea37ef87fd5ddd0e1feed9bc1e852bd4a0a703d49 /doc
parent580c6c399ab18c92da6563fd1f851a74306e0a97 (diff)
parent2dce8c92f6cfc4fb5d6a455fe13cbc0ed6d72882 (diff)
downloadnova-55ccdbc3bc62dc32161112a77c0fed39e73ee7b4.tar.gz
nova-55ccdbc3bc62dc32161112a77c0fed39e73ee7b4.tar.xz
nova-55ccdbc3bc62dc32161112a77c0fed39e73ee7b4.zip
Merge "Remove usage of locals() for formatting from nova.api.*"
Diffstat (limited to 'doc')
-rw-r--r--doc/ext/nova_todo.py8
-rw-r--r--doc/source/devref/il8n.rst13
2 files changed, 9 insertions, 12 deletions
diff --git a/doc/ext/nova_todo.py b/doc/ext/nova_todo.py
index 979a176cf..6f66e2573 100644
--- a/doc/ext/nova_todo.py
+++ b/doc/ext/nova_todo.py
@@ -37,13 +37,13 @@ def process_todo_nodes(app, doctree, fromdocname):
for todo_info in env.todo_all_todos:
para = nodes.paragraph()
- filename = env.doc2path(todo_info['docname'], base=None)
-
# Create a reference
newnode = nodes.reference('', '')
- line_info = todo_info['lineno']
- link = _('%(filename)s, line %(line_info)d') % locals()
+ filename = env.doc2path(todo_info['docname'], base=None)
+ link = (_('%(filename)s, line %(line_info)d') %
+ {'filename': filename, 'line_info': todo_info['lineno']})
+
innernode = nodes.emphasis(link, link)
newnode['refdocname'] = todo_info['docname']
diff --git a/doc/source/devref/il8n.rst b/doc/source/devref/il8n.rst
index 900ea8a28..3b5ea65e9 100644
--- a/doc/source/devref/il8n.rst
+++ b/doc/source/devref/il8n.rst
@@ -9,14 +9,11 @@ in a ``_()`` function call. For example::
LOG.debug(_("block_device_mapping %s"), block_device_mapping)
-If you have multiple arguments, the convention is to use named parameters.
-It's common to use the ``locals()`` dict (which contains the names and values
-of the local variables in the current scope) to do the string interpolation.
-For example::
-
- label = ...
- sr_ref = ...
- LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
+Do not use ``locals()`` for formatting messages because:
+1. It is not as clear as using explicit dicts.
+2. It could produce hidden errors during refactoring.
+3. Changing the name of a variable causes a change in the message.
+4. It creates a lot of otherwise unused variables.
If you do not follow the project conventions, your code may cause the
LocalizationTestCase.test_multiple_positional_format_placeholders test to fail