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

Change subject: [IMPR] Simplyfy Notification.fromJSON
......................................................................

[IMPR] Simplyfy Notification.fromJSON

use try/except to get a value instead of checking for valid keys

Change-Id: Iabdc6769848e6d01d268c700eebefef059c9c2ed
---
M pywikibot/echo.py
1 file changed, 8 insertions(+), 11 deletions(-)

Approvals:
  D3r1ck01: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/echo.py b/pywikibot/echo.py
index 9fb0d33..dfcc45a 100644
--- a/pywikibot/echo.py
+++ b/pywikibot/echo.py
@@ -1,18 +1,16 @@
 # -*- coding: utf-8 -*-
 """Classes and functions for working with the Echo extension."""
 #
-# (C) Pywikibot team, 2014-2019
+# (C) Pywikibot team, 2014-2020
 #
 # Distributed under the terms of the MIT license.
 #
-from __future__ import absolute_import, division, unicode_literals
-
 import pywikibot

 from pywikibot.tools import deprecated


-class Notification(object):
+class Notification:

     """A notification issued by the Echo extension."""

@@ -35,24 +33,23 @@
         notif.timestamp = pywikibot.Timestamp.fromtimestampformat(
             data['timestamp']['mw'])

-        if 'title' in data and 'full' in data['title']:
+        try:
             notif.page = pywikibot.Page(site, data['title']['full'])
-        else:
+        except KeyError:
             notif.page = None

-        if 'agent' in data and 'name' in data['agent']:
+        try:
             notif.agent = pywikibot.User(site, data['agent']['name'])
-        else:
+        except KeyError:
             notif.agent = None

-        if 'read' in data:
+        try:
             notif.read = pywikibot.Timestamp.fromtimestampformat(data['read'])
-        else:
+        except KeyError:
             notif.read = False

         notif.content = data.get('*', None)
         notif.revid = data.get('revid', None)
-
         return notif

     @property

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/617102
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: Iabdc6769848e6d01d268c700eebefef059c9c2ed
Gerrit-Change-Number: 617102
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to