From 336117c1cfe70a046edc694b603e023bf7f808be Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Sun, 5 Jan 2025 17:12:50 +0100 Subject: [PATCH] [Fix] More type hint fixing --- pyerrors/correlators.py | 4 ++-- pyerrors/input/dobs.py | 15 ++++++++------- pyerrors/input/sfcf.py | 1 + pyerrors/obs.py | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index 729cf560..f5ca283d 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -209,7 +209,7 @@ class Corr: newcontent = [None if (item is None) else item[i, j] for item in self.content] return Corr(newcontent) - def plottable(self) -> tuple[list[int], list[float]]: + def plottable(self) -> tuple[list, list, list]: """Outputs the correlator in a plotable format. Outputs three lists containing the timeslice index, the value on each @@ -1415,7 +1415,7 @@ class Corr: return Corr(newcontent) -def _sort_vectors(vec_set_in: list[Optional[ndarray]], ts: int) -> list[Optional[Union[ndarray, list[ndarray]]]]: +def _sort_vectors(vec_set_in: list[Optional[ndarray]], ts: int) -> list[Union[None, ndarray, list[ndarray]]]: """Helper function used to find a set of Eigenvectors consistent over all timeslices""" if isinstance(vec_set_in[ts][0][0], Obs): diff --git a/pyerrors/input/dobs.py b/pyerrors/input/dobs.py index af60eb9c..719773b6 100644 --- a/pyerrors/input/dobs.py +++ b/pyerrors/input/dobs.py @@ -338,8 +338,8 @@ def read_pobs(fname: str, full_output: bool=False, gz: bool=True, separator_inse if gz: if not fname.endswith('.gz'): fname += '.gz' - with gzip.open(fname, 'r') as fin: - content = fin.read() + with gzip.open(fname, 'r') as gin: + content = gin.read() else: if fname.endswith('.gz'): warnings.warn("Trying to read from %s without unzipping!" % fname, UserWarning) @@ -721,7 +721,7 @@ def create_dobs_string(obsl: list[Obs], name: str, spec: str='dobs v1.0', origin symbol = [] if enstags is None: enstags = {} - od = {} + od: dict[str, Any] = {} r_names = [] for o in obsl: r_names += [name for name in o.names if name.split('|')[0] in o.mc_names] @@ -821,7 +821,7 @@ def create_dobs_string(obsl: list[Obs], name: str, spec: str='dobs v1.0', origin ed[''].append(ad) pd['edata'].append(ed) - allcov = {} + allcov: dict[str, ndarray] = {} for o in obsl: for cname in o.cov_names: if cname in allcov: @@ -925,9 +925,10 @@ def write_dobs(obsl: list[Obs], fname: str, name: str, spec: str='dobs v1.0', or if not fname.endswith('.gz'): fname += '.gz' - fp = gzip.open(fname, 'wb') - fp.write(dobsstring.encode('utf-8')) + gp = gzip.open(fname, 'wb') + gp.write(dobsstring.encode('utf-8')) + gp.close() else: fp = open(fname, 'w', encoding='utf-8') fp.write(dobsstring) - fp.close() + fp.close() diff --git a/pyerrors/input/sfcf.py b/pyerrors/input/sfcf.py index d9352785..8feb8989 100644 --- a/pyerrors/input/sfcf.py +++ b/pyerrors/input/sfcf.py @@ -517,6 +517,7 @@ def _find_correlator(file_name: str, version: str, pattern: str, b2b: bool, sile else: start_read = content.count('\n', 0, match.start()) + 5 + b2b end_match = re.search(r'\n\s*\n', content[match.start():]) + assert end_match is not None T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b if not T > 0: raise ValueError("Correlator with pattern\n" + pattern + "\nis empty!") diff --git a/pyerrors/obs.py b/pyerrors/obs.py index cb8d97c7..4ee81d10 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -69,7 +69,7 @@ class Obs: N_sigma_global = 1.0 N_sigma_dict: dict[str, int] = {} - def __init__(self, samples: list[Union[ndarray, list[Any]]], names: list[str], idl: Optional[list[Union[list[int], range]]]=None, **kwargs): + def __init__(self, samples: list[Union[ndarray, list[Any]]], names: list[str], idl: Optional[Union[list[list[int]], list[Union[list[int], range]], list[range]]]=None, **kwargs): """ Initialize Obs object. Parameters