Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 15, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from cleder November 15, 2023 19:03
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

if len(string) <= length:
return string
else:
return string[:length-4] + " ..."
return string if len(string) <= length else f"{string[:length - 4]} ..."
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fit_str refactored with the following changes:

Comment on lines -45 to +48
VERSION = ("Planet/%s +http://www.planetplanet.org" % __version__)
VERSION = f"Planet/{__version__} +http://www.planetplanet.org"

# Default User-Agent header to send when retreiving feeds
USER_AGENT = VERSION + " " + feedparser.USER_AGENT
USER_AGENT = f"{VERSION} {feedparser.USER_AGENT}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 45-48 refactored with the following changes:

Comment on lines -94 to +95
info[key + "_iso"] = time.strftime(TIMEFMT_ISO, date)
info[key + "_822"] = time.strftime(TIMEFMT_822, date)
info[f"{key}_iso"] = time.strftime(TIMEFMT_ISO, date)
info[f"{key}_822"] = time.strftime(TIMEFMT_822, date)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function template_info refactored with the following changes:

time.gmtime(time.time()-86400*activity_threshold)
time.gmtime(time.time()-86400*activity_threshold)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Planet.gather_channel_info refactored with the following changes:

Comment on lines -202 to +215
item_info["channel_" + k] = v
item_info[f"channel_{k}"] = v

# Check for the start of a new day
if prev_date[:3] != newsitem.date[:3]:
prev_date = newsitem.date
item_info["new_date"] = time.strftime(new_date_format,
newsitem.date)

# Check for the start of a new channel
if item_info.has_key("new_date") \
or prev_channel != newsitem._channel:
or prev_channel != newsitem._channel:
prev_channel = newsitem._channel
item_info["new_channel"] = newsitem._channel.url

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Planet.gather_items_info refactored with the following changes:

Comment on lines -927 to +934
for other_key in ("updated", "modified", "published", "issued", "created"):
if self.has_key(other_key):
date = self.get_as_date(other_key)
break
else:
date = None

date = next(
(
self.get_as_date(other_key)
for other_key in (
"updated",
"modified",
"published",
"issued",
"created",
)
if self.has_key(other_key)
),
None,
)
if date is not None:
if date > self._channel.updated:
date = self._channel.updated
# elif date < self._channel.last_updated:
# date = self._channel.updated
date = min(date, self._channel.updated)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NewsItem.get_date refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)
  • Replace comparison with min/max call (min-max-identity)

This removes the following comments ( why? ):

#                date = self._channel.updated
#            elif date < self._channel.last_updated:

Comment on lines -949 to +952
for key in ("content", "tagline", "summary"):
if self.has_key(key) and self.key_type(key) != self.NULL:
return self.get_as_string(key)

return ""
return next(
(
self.get_as_string(key)
for key in ("content", "tagline", "summary")
if self.has_key(key) and self.key_type(key) != self.NULL
),
"",
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NewsItem.get_content refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)

base = tuple(parts[0:i])
base = tuple(parts[:i])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function relativize.collect_and_tally refactored with the following changes:

Comment on lines -80 to +85
if chunks[i] in ['amp', 'lt', 'gt', 'apos', 'quot']:
chunks[i] ='&' + chunks[i] +';'
elif chunks[i] in name2codepoint:
chunks[i]=unichr(name2codepoint[chunks[i]])
else:
chunks[i]='&' + chunks[i] + ';'
if chunks[i] in ['amp', 'lt', 'gt', 'apos', 'quot']:
chunks[i] = f'&{chunks[i]};'
elif chunks[i] in name2codepoint:
chunks[i]=unichr(name2codepoint[chunks[i]])
else:
chunks[i] = f'&{chunks[i]};'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function retype refactored with the following changes:

if self._root:
return key
else:
return self._id + " " + key
return key if self._root else f"{self._id} {key}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CachedInfo.cache_key refactored with the following changes:

Comment on lines -59 to +56
if self._root:
keys_key = " keys"
else:
keys_key = self._id

keys_key = " keys" if self._root else self._id
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CachedInfo.cache_read refactored with the following changes:

del(self._cache[cache_key + " type"])
del self._cache[f"{cache_key} type"]
continue

keys.append(key)
self._cache[cache_key] = self._value[key]
self._cache[cache_key + " type"] = self._type[key]

if self._root:
keys_key = " keys"
else:
keys_key = self._id
self._cache[f"{cache_key} type"] = self._type[key]

keys_key = " keys" if self._root else self._id
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CachedInfo.cache_write refactored with the following changes:

Comment on lines -106 to +104
if self._root:
keys_key = " keys"
else:
keys_key = self._id

if self._cache.has_key(keys_key):
keys = self._cache[keys_key].split(" ")
del(self._cache[keys_key])
else:
keys_key = " keys" if self._root else self._id
if not self._cache.has_key(keys_key):
return

keys = self._cache[keys_key].split(" ")
del(self._cache[keys_key])
for key in keys:
cache_key = self.cache_key(key)
del(self._cache[cache_key])
del(self._cache[cache_key + " type"])
del self._cache[f"{cache_key} type"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CachedInfo.cache_clear refactored with the following changes:

Comment on lines -145 to +140
func = getattr(self, "set_" + key)
func = getattr(self, f"set_{key}")
except AttributeError:
pass
else:
return func(key, value)

if value == None:
if value is None:
return self.set_as_null(key, value)
else:
try:
return self.set_as_string(key, value)
except TypeError:
return self.set_as_date(key, value)
try:
return self.set_as_string(key, value)
except TypeError:
return self.set_as_date(key, value)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CachedInfo.set refactored with the following changes:

Comment on lines -168 to +158
func = getattr(self, "get_" + key)
func = getattr(self, f"get_{key}")
except AttributeError:
pass
else:
return func(key)

try:
func = getattr(self, "get_as_" + self._type[key])
func = getattr(self, f"get_as_{self._type[key]}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CachedInfo.get refactored with the following changes:

Comment on lines -792 to +782
href = attrsD.get('url', attrsD.get('uri', attrsD.get('href', None)))
if href:
if href := attrsD.get('url', attrsD.get('uri', attrsD.get('href', None))):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._itsAnHrefDamnIt refactored with the following changes:

Comment on lines -810 to +805
versionmap = {'0.91': 'rss091u',
'0.92': 'rss092',
'0.93': 'rss093',
'0.94': 'rss094'}
if not self.version:
attr_version = attrsD.get('version', '')
version = versionmap.get(attr_version)
if version:
versionmap = {'0.91': 'rss091u',
'0.92': 'rss092',
'0.93': 'rss093',
'0.94': 'rss094'}
if version := versionmap.get(attr_version):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._start_rss refactored with the following changes:

Comment on lines -844 to +837
versionmap = {'0.1': 'atom01',
'0.2': 'atom02',
'0.3': 'atom03'}
if not self.version:
attr_version = attrsD.get('version')
version = versionmap.get(attr_version)
if version:
self.version = version
else:
self.version = 'atom'
versionmap = {'0.1': 'atom01',
'0.2': 'atom02',
'0.3': 'atom03'}
self.version = version if (version := versionmap.get(attr_version)) else 'atom'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._start_feed refactored with the following changes:

Comment on lines -1008 to +996
context = self.sourcedata
return self.sourcedata
elif self.inentry:
context = self.entries[-1]
return self.entries[-1]
else:
context = self.feeddata
return context
return self.feeddata
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._getContext refactored with the following changes:

Comment on lines -1017 to +1001
context.setdefault(prefix + '_detail', FeedParserDict())
context[prefix + '_detail'][key] = value
context.setdefault(f'{prefix}_detail', FeedParserDict())
context[f'{prefix}_detail'][key] = value
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._save_author refactored with the following changes:

Comment on lines -1028 to +1015
detail = context.get('%s_detail' % key)
if detail:
if detail := context.get(f'{key}_detail'):
name = detail.get('name')
email = detail.get('email')
if name and email:
context[key] = '%s (%s)' % (name, email)
context[key] = f'{name} ({email})'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._sync_author_detail refactored with the following changes:

Comment on lines -1082 to +1064
id = self._getAttribute(attrsD, 'rdf:about')
if id:
if id := self._getAttribute(attrsD, 'rdf:about'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._start_item refactored with the following changes:

Comment on lines -1156 to +1137
value = self._getAttribute(attrsD, 'rdf:resource')
if value:
if value := self._getAttribute(attrsD, 'rdf:resource'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._start_cc_license refactored with the following changes:

Comment on lines -1327 to +1307
value = self._getAttribute(attrsD, 'rdf:resource')
if value:
if value := self._getAttribute(attrsD, 'rdf:resource'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._start_admin_errorreportsto refactored with the following changes:

Comment on lines -1353 to +1332
href = attrsD.get('href')
if href:
if href := attrsD.get('href'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedParserMixin._start_enclosure refactored with the following changes:

Comment on lines -1770 to +1739
if ((code / 100) == 3) and (code != 304):
if code == 300:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _FeedURLHandler.http_error_default refactored with the following changes:

Comment on lines -1866 to +1835
url_file_stream_or_string = '%s://%s%s' % (urltype, realhost, rest)
url_file_stream_or_string = f'{urltype}://{realhost}{rest}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _open_resource refactored with the following changes:

Comment on lines -1957 to +1926
if ordinal:
ordinal = int(ordinal)
else:
ordinal = 0
ordinal = int(ordinal) if ordinal else 0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _parse_date_iso8601 refactored with the following changes:

This removes the following comments ( why? ):

# ordinals are NOT normalized by mktime, we simulate them
# by setting month=1, day=ordinal
# see above

Comment on lines -2062 to +2021
hour = '0' + hour
hour = f'0{hour}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _parse_date_nate refactored with the following changes:

Comment on lines -2168 to +2130
day = '0' + day
day = f'0{day}'
hour = m.group(4)
if len(hour) == 1:
hour = '0' + hour
hour = f'0{hour}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _parse_date_hungarian refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants