jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/566604 )
Change subject: [IMPR] use dict.setdefault and reduce code complexity ......................................................................
[IMPR] use dict.setdefault and reduce code complexity
Change-Id: Ib3b0572303bf87bc1a03fc51ffc008768eef0706 --- M pywikibot/data/api.py M pywikibot/page.py M pywikibot/site.py M pywikibot/userinterfaces/terminal_interface_base.py 4 files changed, 7 insertions(+), 13 deletions(-)
Approvals: Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 5b0bb63..02d3cfd 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Interface to Mediawiki's api.php.""" # -# (C) Pywikibot team, 2007-2019 +# (C) Pywikibot team, 2007-2020 # # Distributed under the terms of the MIT license. # @@ -1350,8 +1350,7 @@ cls._warn_kwargs() else: kwargs = dict(kwargs) - if 'parameters' not in kwargs: - kwargs['parameters'] = {} + kwargs.setdefault('parameters', {}) return kwargs
def _format_value(self, value): diff --git a/pywikibot/page.py b/pywikibot/page.py index b675f66..aea88fa 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -5277,8 +5277,7 @@ assert source.isReference is True src_data = source.toJSON() if 'hash' in src_data: - if 'hash' not in reference: - reference['hash'] = src_data['hash'] + reference.setdefault('hash', src_data['hash']) del src_data['hash'] reference['snaks'][prop].append(src_data) data['references'].append(reference) diff --git a/pywikibot/site.py b/pywikibot/site.py index 69fe186..6c17139 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -2648,8 +2648,7 @@ custom_name = nsdata.pop('*') canonical_name = nsdata.pop('canonical')
- if 'content' not in nsdata: # mw < 1.16 - nsdata['content'] = ns == 0 + nsdata.setdefault('content', ns == 0) # mw < 1.16
default_case = Namespace.default_case(ns) if 'case' not in nsdata: @@ -6588,8 +6587,7 @@ else: return False result = data - if 'offset' not in result: - result['offset'] = 0 + result.setdefault('offset', 0) break throttle = False if 'offset' in data: @@ -6653,8 +6651,7 @@ _file_key = None pywikibot.warning('No filekey defined.') if not report_success: - if 'offset' not in result: - result['offset'] = True + result.setdefault('offset', True) if ignore_warnings(create_warnings_list(result)): return self.upload( filepage, source_filename, source_url, comment, text, diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py index e1bc4bf..3e7e6e2 100755 --- a/pywikibot/userinterfaces/terminal_interface_base.py +++ b/pywikibot/userinterfaces/terminal_interface_base.py @@ -515,8 +515,7 @@ if 'message' in record.__dict__: return
- if 'newline' not in record.__dict__: - record.__dict__['newline'] = '\n' + record.__dict__.setdefault('newline', '\n')
text = self.format(record) return self.UI.output(text, targetStream=self.stream)