Skip to content

Commit

Permalink
use specific types for return of abstract method when possible
Browse files Browse the repository at this point in the history
use more general type when necessary
  • Loading branch information
CunliangGeng committed Jun 14, 2024
1 parent 36a474d commit 621635a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/nplinker/genomics/abc.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from abc import ABC
from abc import abstractmethod
from typing import Mapping
from typing import Sequence
from .bgc import BGC
from .gcf import GCF


class BGCLoaderBase(ABC):
"""Abstract base class for BGC loader."""

def __init__(self, data_dir: str):
def __init__(self, data_dir: str) -> None:
"""Initialize the BGC loader.
Args:
Expand All @@ -19,15 +17,15 @@ def __init__(self, data_dir: str):
self.data_dir = data_dir

@abstractmethod
def get_files(self) -> Mapping[str, str]:
def get_files(self) -> dict[str, str]:
"""Get path to BGC files.
Returns:
The key is BGC name and value is path to BGC file
"""

@abstractmethod
def get_bgcs(self) -> Sequence[BGC]:
def get_bgcs(self) -> list[BGC]:
"""Get BGC objects.
Returns:
Expand All @@ -39,7 +37,7 @@ class GCFLoaderBase(ABC):
"""Abstract base class for GCF loader."""

@abstractmethod
def get_gcfs(self, keep_mibig_only: bool, keep_singleton: bool) -> Sequence[GCF]:
def get_gcfs(self, keep_mibig_only: bool, keep_singleton: bool) -> list[GCF]:
"""Get GCF objects.
Args:
Expand Down
10 changes: 4 additions & 6 deletions src/nplinker/metabolomics/abc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from abc import ABC
from abc import abstractmethod
from typing import Mapping
from typing import Sequence
from .molecular_family import MolecularFamily
from .spectrum import Spectrum

Expand All @@ -11,7 +9,7 @@ class SpectrumLoaderBase(ABC):

@property
@abstractmethod
def spectra(self) -> Sequence["Spectrum"]:
def spectra(self) -> list["Spectrum"]:
"""Get Spectrum objects.
Returns:
Expand All @@ -23,7 +21,7 @@ class MolecularFamilyLoaderBase(ABC):
"""Abstract base class for MolecularFamilyLoader."""

@abstractmethod
def get_mfs(self, keep_singleton: bool) -> Sequence["MolecularFamily"]:
def get_mfs(self, keep_singleton: bool) -> list["MolecularFamily"]:
"""Get MolecularFamily objects.
Args:
Expand All @@ -41,7 +39,7 @@ class FileMappingLoaderBase(ABC):

@property
@abstractmethod
def mappings(self) -> Mapping[str, Sequence[str]]:
def mappings(self) -> dict[str, list[str]]:
"""Get file mappings.
Returns:
Expand All @@ -54,7 +52,7 @@ class AnnotationLoaderBase(ABC):

@property
@abstractmethod
def annotations(self) -> Mapping[str, Mapping]:
def annotations(self) -> dict[str, dict]:
"""Get annotations.
Returns:
Expand Down

0 comments on commit 621635a

Please sign in to comment.