Skip to content

Commit

Permalink
Merge pull request #102 from kurtmckee/no-else-return
Browse files Browse the repository at this point in the history
Remove unnecessary `elif` and `else` branches
  • Loading branch information
kurtmckee authored Jul 29, 2024
2 parents 409b428 + 545399b commit 3430d5c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/listparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ def parse(parse_obj: str | bytes) -> common.SuperDict:
def get_content(obj: bytes | str) -> tuple[bytes | None, dict[str, t.Any]]:
if isinstance(obj, bytes):
return obj, {"bozo": False, "bozo_exception": None}
elif not isinstance(obj, str):
if not isinstance(obj, str):
# Only str and bytes objects can be parsed.
error = ListparserError("parse() called with unparsable object")
return None, {"bozo": True, "bozo_exception": error}
elif not obj.startswith(("http://", "https://")):
if not obj.startswith(("http://", "https://")):
# It's not a URL, so it must be treated as an XML document.
return obj.encode("utf8"), {
"bozo": False,
"bozo_exception": None,
}

# It's a URL. Confirm requests is installed.
elif requests is None:
if requests is None:
message = f"requests is not installed so {obj} cannot be retrieved"
return None, {
"bozo": True,
Expand Down
3 changes: 1 addition & 2 deletions src/listparser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class SuperDict(t.Dict[str, t.Any]):
def __getattribute__(self, name: str) -> t.Any:
if name in self:
return self[name]
else:
return dict.__getattribute__(self, name)
return dict.__getattribute__(self, name)


class Common(XMLHandler):
Expand Down
3 changes: 1 addition & 2 deletions src/listparser/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def parse_rfc822(date: str) -> datetime.datetime | None:
day = int(parts[1])
except ValueError:
return None
else:
parts[1] = parts[0]
parts[1] = parts[0]
else:
return None
month = months.get(parts[1][:3])
Expand Down

0 comments on commit 3430d5c

Please sign in to comment.