diff options
| author | Boris Pavlovic <boris@pavlovic.me> | 2013-05-17 17:38:51 +0400 |
|---|---|---|
| committer | Boris Pavlovic <boris@pavlovic.me> | 2013-05-18 00:04:17 +0400 |
| commit | 2dce8c92f6cfc4fb5d6a455fe13cbc0ed6d72882 (patch) | |
| tree | 2bee70e0e0d4847b20dad29500600825b20c06d7 /doc/source | |
| parent | f124d50024fbddb56733831149012f6f4c9c3e6e (diff) | |
| download | nova-2dce8c92f6cfc4fb5d6a455fe13cbc0ed6d72882.tar.gz nova-2dce8c92f6cfc4fb5d6a455fe13cbc0ed6d72882.tar.xz nova-2dce8c92f6cfc4fb5d6a455fe13cbc0ed6d72882.zip | |
Remove usage of locals() for formatting from nova.api.*
Using of locals() for formatting string is a nasty thing because:
1) It is not so clear as using explicit dicts
2) It could produce hidden errors during refactoring
3) Changing name of variable causes change in message
4) Creating a lot of unused variables
fixes bug 1171936
Change-Id: I293d7ebb875f65cce322d4938d1ae323f3aded8d
Diffstat (limited to 'doc/source')
| -rw-r--r-- | doc/source/devref/il8n.rst | 13 |
1 files changed, 5 insertions, 8 deletions
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 |
