Skip to content

Commit

Permalink
use comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
barrust committed Jan 7, 2024
1 parent c1ed5e6 commit 5f4cfe2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 3 additions & 4 deletions mediawiki/mediawiki.py
Expand Up @@ -223,7 +223,6 @@ def timeout(self) -> float:
@timeout.setter
def timeout(self, timeout: float):
"""Set request timeout in seconds (or fractions of a second)"""

self._timeout = None if timeout is None else float(timeout)

@property
Expand Down Expand Up @@ -881,9 +880,8 @@ def _get_site_info(self):

api_version = gen["generator"].split(" ")[1].split("-")[0]

major_minor = api_version.split(".")
for i, item in enumerate(major_minor):
major_minor[i] = int(item)
major_minor = [int(i) for i in api_version.split(".")]

self._api_version = tuple(major_minor)
self._api_version_str = ".".join([str(x) for x in self._api_version])

Expand Down Expand Up @@ -969,6 +967,7 @@ def __cat_tree_rec(
raise exc
except Exception:
tries = tries + 1
# TODO: Should this really sleep?
time.sleep(1)
else:
parent_cats = categories[cat].categories
Expand Down
6 changes: 3 additions & 3 deletions mediawiki/mediawikipage.py
Expand Up @@ -253,18 +253,17 @@ def images(self) -> List[str]:
Note:
Not settable"""
if self._images is None:
self._images = []
params = {
"generator": "images",
"gimlimit": "max",
"prop": "imageinfo", # this will be replaced by fileinfo
"iiprop": "url",
}
self._images.extend(
self._images = [
page["imageinfo"][0]["url"]
for page in self._continued_query(params)
if "imageinfo" in page and "url" in page["imageinfo"][0]
)
]
self._images = sorted(self._images)
return self._images

Expand Down Expand Up @@ -527,6 +526,7 @@ def section(self, section_title: Optional[str]) -> Optional[str]:
else:
section = f"== {section_title} =="
try:
# TODO, move index to find to remove exceptions
content = self.content
index = content.index(section) + len(section)

Expand Down
4 changes: 1 addition & 3 deletions mediawiki/utilities.py
Expand Up @@ -75,6 +75,4 @@ def str_or_unicode(text: str) -> str:

def is_relative_url(url: str) -> Optional[bool]:
"""simple method to determine if a url is relative or absolute"""
if url.startswith("#"):
return None
return url.find("://") <= 0 and not url.startswith("//")
return url.find("://") <= 0 and not url.startswith("//") if not url.startswith("#") else None

0 comments on commit 5f4cfe2

Please sign in to comment.