Skip to content

Commit

Permalink
[IMPR] simplify Siteinfo._get_siteinfo
Browse files Browse the repository at this point in the history
Decrease nested flow statements after exception cause is either
raised or a return statement leaves it.

Change-Id: I3395dc9b9aa11e26683f98e0ee0aa1fe4bcda158
  • Loading branch information
xqt committed Feb 4, 2024
1 parent 1452451 commit d3e1924
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions pywikibot/site/_siteinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,34 @@ def warn_handler(mod, message) -> bool:
except APIError as e:
if e.code == 'siunknown_siprop':
if len(props) == 1:
pywikibot.log(
f"Unable to get siprop '{props[0]}'")
pywikibot.log(f"Unable to get siprop '{props[0]}'")
return {props[0]: (EMPTY_DEFAULT, False)}

pywikibot.log('Unable to get siteinfo, because at least '
"one property is unknown: '{}'".format(
"', '".join(props)))
"one property is unknown: '{}'"
.format("', '".join(props)))
results = {}
for prop in props:
results.update(self._get_siteinfo(prop, expiry))
return results
raise
else:
result = {}
if invalid_properties:
for prop in invalid_properties:
result[prop] = (EMPTY_DEFAULT, False)
pywikibot.log("Unable to get siprop(s) '{}'".format(
"', '".join(invalid_properties)))
if 'query' in data:
# If the request is a CachedRequest, use the _cachetime attr.
cache_time = getattr(
request, '_cachetime', None) or datetime.datetime.utcnow()
for prop in props:
if prop in data['query']:
self._post_process(prop, data['query'][prop])
result[prop] = (data['query'][prop], cache_time)
return result

result = {}
if invalid_properties:
for prop in invalid_properties:
result[prop] = (EMPTY_DEFAULT, False)
pywikibot.log("Unable to get siprop(s) '{}'"
.format("', '".join(invalid_properties)))

if 'query' in data:
# If the request is a CachedRequest, use the _cachetime attr.
cache_time = getattr(
request, '_cachetime', None) or datetime.datetime.utcnow()
for prop in props:
if prop in data['query']:
self._post_process(prop, data['query'][prop])
result[prop] = (data['query'][prop], cache_time)
return result

@staticmethod
def _is_expired(cache_date, expire):
Expand Down

0 comments on commit d3e1924

Please sign in to comment.