Skip to content

Commit

Permalink
some type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Feb 28, 2023
1 parent 470e2ef commit e5194e1
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions obonet/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import itertools
import logging
import re
from typing import Any

import networkx

Expand All @@ -13,7 +14,7 @@

def read_obo(
path_or_file, ignore_obsolete: bool = True, encoding: str | None = "utf-8"
):
) -> networkx.MultiDiGraph[str]:
"""
Return a networkx.MultiDiGraph of the ontology serialized by the
specified path or file.
Expand All @@ -29,7 +30,7 @@ def read_obo(
ignore_obsolete : boolean
When true (default), terms that are marked 'is_obsolete' will
not be added to the graph.
encoding : str of None
encoding : str or None
The character set encoding to use for path_or_file when path_or_file
is a path/URL. Set to None for platform-dependent locale default.
"""
Expand Down Expand Up @@ -67,7 +68,11 @@ def read_obo(
return graph


def get_sections(lines):
def get_sections(
lines,
) -> tuple[
list[dict[str, Any]], list[dict[str, Any]], list[dict[str, Any]], dict[str, Any]
]:
"""
Separates an obo file into stanzas and process.
Returns (typedefs, terms, instances, header) tuples
Expand Down Expand Up @@ -106,7 +111,7 @@ def get_sections(lines):
) # noqa: E501


def parse_tag_line(line):
def parse_tag_line(line: str) -> tuple[str, str | None, str | None, str | None]:
"""
Take a line representing a single tag-value pair and parse
the line into (tag, value, trailing_modifier, comment).
Expand All @@ -126,7 +131,7 @@ def parse_tag_line(line):
return tag, value, trailing_modifier, comment


def parse_stanza(lines, tag_singularity):
def parse_stanza(lines, tag_singularity) -> dict[str, Any]:
"""
Returns a dictionary representation of a stanza.
"""
Expand Down

0 comments on commit e5194e1

Please sign in to comment.