jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/808416 )

Change subject: [IMPR] Improve PropertyGenerator._update_old_result_dict
......................................................................

[IMPR] Improve PropertyGenerator._update_old_result_dict

- add str, int or list to old_dict only
- raise a ValueError if there is an unexpected type instead of
  an AssertionError
- print the unexpected type instead of the value

Change-Id: Iff2ec59c19542f7358b412fb19e63d1a3f7a6089
---
M pywikibot/data/api/_generators.py
1 file changed, 8 insertions(+), 8 deletions(-)

Approvals:
  Matěj Suchánek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/data/api/_generators.py 
b/pywikibot/data/api/_generators.py
index e2b4a10..254fd78 100644
--- a/pywikibot/data/api/_generators.py
+++ b/pywikibot/data/api/_generators.py
@@ -763,14 +763,14 @@
     def _update_old_result_dict(old_dict, new_dict) -> None:
         """Update old result dict with new_dict."""
         for k, v in new_dict.items():
-            if k not in old_dict:
-                old_dict[k] = v
-                continue
-            if isinstance(v, list):
-                old_dict[k].extend(v)
-                continue
-            assert isinstance(v, (str, int)), (
-                'continued API result had an unexpected type: {}'.format(v))
+            if isinstance(v, (str, int)):
+                old_dict.setdefault(k, v)
+            elif isinstance(v, list):
+                old_dict.setdefault(k, []).extend(v)
+            else:
+                raise ValueError(
+                    'continued API result had an unexpected type: {}'
+                    .format(type(v).__name__))


 class ListGenerator(QueryGenerator):

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/808416
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Iff2ec59c19542f7358b412fb19e63d1a3f7a6089
Gerrit-Change-Number: 808416
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to