XZise has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/244430

Change subject: [IMPROV] i18n: Deprecate non-mapping parameters
......................................................................

[IMPROV] i18n: Deprecate non-mapping parameters

Not using mapping parameters should be avoided when the text contains multiple
of them, as they might change order. And for consistency also translations
with only one parameter should use a mapping.

Change-Id: I60b32e4e415ed151458a484911a0cb222e2ab9c5
---
M pywikibot/i18n.py
1 file changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/30/244430/1

diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index ee2bb92..212906d 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -33,7 +33,7 @@
 import os
 import pkgutil
 
-from collections import defaultdict
+from collections import defaultdict, Mapping
 
 import pywikibot
 
@@ -41,6 +41,7 @@
 from pywikibot import Error
 from pywikibot import config
 from pywikibot.plural import plural_rules
+from pywikibot.tools import issue_deprecation_warning
 
 if sys.version_info[0] > 2:
     basestring = (str, )
@@ -448,6 +449,9 @@
     if parameters is None:
         return trans
 
+    if not isinstance(parameters, Mapping):
+        issue_deprecation_warning('parameters not being a mapping', None, 2)
+
     # else we check for PLURAL variants
     trans = _extract_plural(code, trans, parameters)
     if parameters:
@@ -470,7 +474,8 @@
 
     @param code: The language code
     @param twtitle: The TranslateWiki string title, in <package>-<key> format
-    @param parameters: For passing parameters.
+    @param parameters: For passing parameters. It should be a mapping but for
+        backwards compatibility can also be a list, tuple or a single value.
     @param fallback: Try an alternate language code
     @type fallback: boolean
     """
@@ -512,6 +517,10 @@
     # send the language code back via the given list
     if code_needed:
         code.append(alt)
+
+    if parameters is not None and not isinstance(parameters, Mapping):
+        issue_deprecation_warning('parameters not being a Mapping', None, 2)
+
     if parameters:
         return trans % parameters
     else:

-- 
To view, visit https://gerrit.wikimedia.org/r/244430
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I60b32e4e415ed151458a484911a0cb222e2ab9c5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <commodorefabia...@gmx.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to