jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1154396?usp=email )
Change subject: IMPR: raise TypeError instead of ValueError if parameter is not
a mapping
......................................................................
IMPR: raise TypeError instead of ValueError if parameter is not a mapping
Also update documentaiton.
Change-Id: I8e7af3de76aa51c58b9540aece2500a3af7d6c05
---
M pywikibot/i18n.py
1 file changed, 17 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 2b461cb..a045df0 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -560,16 +560,25 @@
"""Return the most appropriate localization from a localization dict.
Given a site code and a dictionary, returns the dictionary's value
- for key 'code' if this key exists; otherwise tries to return a value
+ for key *code* if this key exists; otherwise tries to return a value
for an alternative code that is most applicable to use on the wiki
- in language 'code' except fallback is False.
+ in language *code* except fallback is False.
- The code itself is always checked first, then these codes that have
+ The *code* itself is always checked first, then these codes that have
been defined to be alternatives, and finally English.
- If fallback is False and the code is not found in the
+ If *fallback* is False and the code is not found in the *xdict*,
+ None is returned.
- For PLURAL support have a look at the twtranslate method.
+ For PLURAL support have a look at the :func:`twtranslate` function.
+
+ .. versionchanged:: 2.0
+ *parameter* other than a mapping (or None) is deprecated.
+ .. versionchanged:: 6.2
+ ValueError is raised if *parameter* is not a mapping.
+ .. versionchanged:: 10.2
+ TypeError instead of ValueError is raised if *parameter* is not a
+ mapping.
:param code: The site code as string or Site object. If xdict is an
extended dictionary the Site object should be used in favour of
@@ -586,9 +595,10 @@
:raise IndexError: If the language supports and requires more
plurals than defined for the given PLURAL pattern.
:raise KeyError: No fallback key found if fallback is not False
+ :raise TypeError: *parameter* is not a mapping
"""
family = pywikibot.config.family
- # If a site is given instead of a code, use its language
+ # If a site is given instead of a code, use its code
if hasattr(code, 'code'):
family = code.family.name
code = code.code
@@ -636,7 +646,7 @@
return trans
if not isinstance(parameters, Mapping):
- raise ValueError(
+ raise TypeError(
f'parameters should be a mapping, not {type(parameters).__name__}'
)
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1154396?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I8e7af3de76aa51c58b9540aece2500a3af7d6c05
Gerrit-Change-Number: 1154396
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]