Skip to content

Commit

Permalink
Update type hints for new beautifulsoup4 (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt authored Feb 4, 2025
1 parent 4e7558a commit c8bebc5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/pyobo/sources/bigg/bigg_compartment.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ def get_compartments(*, force: bool = False, version: str | None = None) -> dict
"""Get a dictionary of BiGG compartments."""
rv = {}
soup = get_soup(DATA_URL)
table = soup.find(**{"class": "myTable"})
for row in table.findAll("tr"):
cells = list(row.findAll("td"))
table = soup.find(**{"class": "myTable"}) # type:ignore[arg-type]
if table is None:
raise ValueError
for row in table.find_all("tr"): # type:ignore[attr-defined]
cells = list(row.find_all("td"))
if not cells:
continue
identifier_cell, name_cell = cells
Expand Down
13 changes: 10 additions & 3 deletions src/pyobo/sources/omim_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"OMIMPSGetter",
]


logger = logging.getLogger(__name__)
PREFIX = "omim.ps"
URL = "https://omim.org/phenotypicSeriesTitles/all"
Expand All @@ -25,8 +24,16 @@ class OMIMPSGetter(Obo):
def iter_terms(self, force: bool = False) -> Iterable[Term]:
"""Iterate over terms in the ontology."""
soup = get_soup(URL, user_agent="Mozilla/5.0")
rows = soup.find(id="mimContent").find("table").find("tbody").find_all("tr")
for row in rows:
content = soup.find(id="mimContent")
if content is None:
raise ValueError
table = content.find("table") # type:ignore[attr-defined]
if table is None:
raise ValueError
tbody = table.find("tbody")
if tbody is None:
raise ValueError
for row in tbody.find_all("tr"):
anchor = row.find("td").find("a")
name = anchor.text.strip()
identifier = anchor.attrs["href"][len("/phenotypicSeries/") :]
Expand Down
6 changes: 5 additions & 1 deletion src/pyobo/sources/umls/get_synonym_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def get_umls_synonyms(*, refresh: bool = False) -> Mapping[str, str]:
res = requests.get(ABBREVIATIONS_URL, timeout=5)
soup = BeautifulSoup(res.text, features="html.parser")
table = soup.find(id="mrdoc_TTY")
body = table.find("tbody")
if table is None:
raise ValueError
body = table.find("tbody") # type:ignore[attr-defined]
if body is None:
raise ValueError
rv = {}
for row in body.find_all("tr"):
left, right = row.find_all("td")
Expand Down

0 comments on commit c8bebc5

Please sign in to comment.