Skip to content

Commit

Permalink
fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
barrust committed Jan 6, 2024
1 parent 941c1d3 commit dfad82c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mediawiki/mediawiki.py
Expand Up @@ -949,7 +949,7 @@ def _check_query(value, message: str):
raise ValueError(message)

@staticmethod
def __category_parameter_verification(cats: list[str], depth: int, category: str):
def __category_parameter_verification(cats, depth, category):
# parameter verification
if len(cats) == 1 and (cats[0] is None or cats[0] == ""):
msg = (
Expand Down
11 changes: 8 additions & 3 deletions mediawiki/mediawikipage.py
Expand Up @@ -504,7 +504,7 @@ def table_of_contents(self) -> Dict[str, Any]:
self._table_of_contents = {}
return self._table_of_contents

def section(self, section_title: str) -> Optional[str]:
def section(self, section_title: Optional[str]) -> Optional[str]:
"""Plain text section content
Args:
Expand Down Expand Up @@ -550,7 +550,10 @@ def section(self, section_title: str) -> Optional[str]:
except ValueError:
next_index = len(self.content)

return self.content[index:next_index].lstrip("=").strip()
val = self.content[index:next_index].lstrip("=").strip()
if val == "":
return None
return val

def parse_section_links(self, section_title: str) -> Optional[List[Tuple[str, str]]]:
"""Parse all links within a section
Expand Down Expand Up @@ -767,9 +770,11 @@ def _parse_section_links(self, id_tag: Optional[str]) -> List[Tuple[str, str]]:
all_links.append(self.__parse_link_info(link))
return all_links

def __parse_link_info(self, link: str) -> Tuple[str, str]:
def __parse_link_info(self, link: Tag) -> Tuple[str, str]:
"""parse the <a> tag for the link"""
href = link.get("href", "")
if isinstance(href, list):
href = href[0]
txt = link.string or href
is_rel = is_relative_url(href)
if is_rel is True:
Expand Down
4 changes: 2 additions & 2 deletions mediawiki/utilities.py
Expand Up @@ -5,7 +5,7 @@
import inspect
import sys
import time
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, Optional


def parse_all_arguments(func: Callable) -> Dict[str, Any]:
Expand Down Expand Up @@ -73,7 +73,7 @@ def str_or_unicode(text: str) -> str:
return text.encode(encoding).decode(encoding)


def is_relative_url(url: str) -> bool:
def is_relative_url(url: str) -> Optional[bool]:
"""simple method to determine if a url is relative or absolute"""
if url.startswith("#"):
return None
Expand Down

0 comments on commit dfad82c

Please sign in to comment.