jenkins-bot submitted this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[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(-)

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 change 808416. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Iff2ec59c19542f7358b412fb19e63d1a3f7a6089
Gerrit-Change-Number: 808416
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged