Skip to content

Commit

Permalink
[REF] translation-positional-used: Consider srt.format('{} {}') cases
Browse files Browse the repository at this point in the history
  • Loading branch information
moylop260 committed Oct 20, 2022
1 parent c0186df commit 65d0a40
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pylint_odoo/checkers/no_modules.py
Expand Up @@ -792,7 +792,10 @@ def visit_call(self, node):
printf_args = (
misc.WrapperModuleChecker.
_get_printf_str_args_kwargs(str2translate))
if isinstance(printf_args, tuple) and len(printf_args) >= 2:
format_args = (
misc.WrapperModuleChecker._get_format_str_args_kwargs(str2translate)[0])
if (isinstance(printf_args, tuple) and len(printf_args) >= 2 or
len(format_args) >= 2):
# Return tuple for %s and dict for %(varname)s
# Check just the following cases "%s %s..."
self.add_message('translation-positional-used',
Expand Down
5 changes: 3 additions & 2 deletions pylint_odoo/misc.py
Expand Up @@ -612,8 +612,9 @@ def _get_format_str_args_kwargs(format_str):
# named "{var0} {var1} {var2} {var0}"
format_str_kwargs[placeholder] = 0
if format_str_args:
format_str_args = (range(len(format_str_args)) if max(format_str_args) == 0
else range(max(format_str_args)))
format_str_args = (
list(range(len(format_str_args))) if max(format_str_args) == 0
else list(range(max(format_str_args))))
return format_str_args, format_str_kwargs

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion pylint_odoo/test/main.py
Expand Up @@ -64,7 +64,7 @@
'translation-field': 2,
'translation-required': 15,
'translation-contains-variable': 10,
'translation-positional-used': 5,
'translation-positional-used': 7,
'use-vim-comment': 1,
'wrong-tabs-instead-of-spaces': 2,
'eval-referenced': 5,
Expand Down
4 changes: 4 additions & 0 deletions pylint_odoo/test_repo/broken_module/models/broken_model.py
Expand Up @@ -302,12 +302,16 @@ def my_method1(self, variable1):
# so you can't change the order in the translation
_('%s %d') % ('hello', 3)
_('%s %s') % ('hello', 'world')
_('{} {}').format('hello', 3)
_('{} {}').format('hello', 'world')

# Valid cases
_('%(strname)s') % {'strname': 'hello'}
_('%(strname)s %(intname)d') % {'strname': 'hello', 'intname': 3}
_('%s') % 'hello'
_('%d') % 3
_('{}').format('hello')
_('{}').format(3)
return error_msg

def my_method2(self, variable2):
Expand Down

0 comments on commit 65d0a40

Please sign in to comment.