Skip to content

Commit

Permalink
Try to fix again the py39 isinstance issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
chtsai0105 committed May 3, 2024
1 parent 9a38202 commit ad8d7d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/phyling/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import textwrap
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Generic, Iterable, Iterator, Sequence, TypeVar, Union
from typing import Generic, Iterable, Iterator, Sequence, TypeVar

import phyling.config as config
import phyling.exception as exception
Expand Down Expand Up @@ -103,7 +103,7 @@ class DataListABC(ABC, Generic[T]):
def __init__(self, files: Iterator[str | Path | T] | Sequence[str | Path | T]) -> None:
"""Initialize the object and store data into a list."""
self.data: list[T] = []
if not isinstance(files, Union[Iterator, tuple, list]):
if not isinstance(files, (Iterator, tuple, list)):
raise TypeError(f"{self.__class__.__qualname__} is not an iterator/tuple/list")

def __repr__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions src/phyling/libphyling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from io import BytesIO, StringIO
from multiprocessing.dummy import Pool
from pathlib import Path
from typing import AnyStr, Iterable, Sequence, Union
from typing import AnyStr, Iterable, Sequence

import numpy as np
import pyhmmer
Expand Down Expand Up @@ -190,7 +190,7 @@ def __init__(self, files: Iterable[str | Path | SampleSeqs]) -> None:
for item in files:
if isinstance(item, SampleSeqs):
self.data.append(item)
elif isinstance(item, Union[str, Path]):
elif isinstance(item, (str, Path)):
self.data.append(SampleSeqs(item))
else:
raise TypeError(f"{self.__class__.__qualname__} only accepts list of str/Path/SampleSeqs")
Expand Down Expand Up @@ -285,7 +285,7 @@ class HMMMarkerSet(_abc.DataListABC[pyhmmer.plan7.HMM]):

def __init__(self, folder: str | Path, cutoff: str | Path | None = None, *, raise_err: bool = True):
"""Initialize the object and perform seqtype and duplicated name checks."""
if isinstance(folder, Union[str, Path]):
if isinstance(folder, (str, Path)):
folder = Path(folder)
else:
raise TypeError('Argument "folder" only accepts of str or Path.')
Expand Down
10 changes: 6 additions & 4 deletions src/phyling/phylotree.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from itertools import product
from multiprocessing.dummy import Pool
from pathlib import Path
from typing import Iterable, Union
from typing import Iterator, Sequence

import matplotlib.pyplot as plt
from Bio import AlignIO, Phylo, SeqIO
Expand Down Expand Up @@ -393,7 +393,7 @@ def __init__(self, files: list[str | Path | MFA2Tree], *, seqtype: str | None =
"""Initialize the wrapper object."""
super().__init__(files)
for file in files:
if isinstance(file, Union[str, Path]):
if isinstance(file, (str, Path)):
data = MFA2Tree(file, seqtype=seqtype)
elif isinstance(file, MFA2Tree):
data = file
Expand Down Expand Up @@ -512,7 +512,9 @@ def get_consensus_tree(self) -> Tree:
@_utils.timing
@Decorator.check_sorted
@Decorator.check_single_file
def concat(self, output: Path, samples: Iterable[str] | None, *, partition: str | None = None, threads: int = 1) -> MFA2Tree:
def concat(
self, output: Path, samples: Iterator[str] | Sequence[str] | None, *, partition: str | None = None, threads: int = 1
) -> MFA2Tree:
"""Concatenate selected MSAs to a single mfa file and return the corresponding MFA2Tree object."""
alignmentList = [mfa2tree.msa for mfa2tree in self]
# Sort by MSA length, since shorter MSA might have higher chances to have missing states
Expand Down Expand Up @@ -563,7 +565,7 @@ def concat(self, output: Path, samples: Iterable[str] | None, *, partition: str
return MFA2Tree(concat_file, partition=partition_file, seqtype=self.seqtype)

@staticmethod
def _fill_missing_taxon(samples: Iterable[str], alignment: MultipleSeqAlignment) -> MultipleSeqAlignment:
def _fill_missing_taxon(samples: Iterator[str] | Sequence[str], alignment: MultipleSeqAlignment) -> MultipleSeqAlignment:
"""Include empty gap-only strings to the alignment for taxa lacking an ortholog."""
missing = set(samples) - {seq.id for seq in alignment}
for sample in missing:
Expand Down

0 comments on commit ad8d7d2

Please sign in to comment.