Skip to content

Commit 109aa38

Browse files
committed
Add missing type hints
1 parent 7927063 commit 109aa38

34 files changed

Lines changed: 270 additions & 227 deletions

mh_utils/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# stdlib
3030
from abc import abstractmethod
31-
from typing import Dict, Iterable, Iterator, Tuple, TypeVar
31+
from typing import Any, Iterable, Iterator, Mapping, Tuple, TypeVar
3232

3333
# 3rd party
3434
from domdf_python_tools._is_match import is_match_with
@@ -68,27 +68,27 @@ def __iter__(self) -> Iterator[Tuple[str, _V]]:
6868

6969
yield from self.to_dict().items()
7070

71-
def __getstate__(self) -> Dict[str, _V]:
71+
def __getstate__(self) -> Mapping[str, _V]:
7272
return self.to_dict()
7373

74-
def __setstate__(self, state):
74+
def __setstate__(self, state) -> None: # noqa: MAN001
7575
self.__init__(**state) # type: ignore[misc]
7676

77-
def __copy__(self):
77+
def __copy__(self) -> "Dictable":
7878
return self.__class__(**self.to_dict())
7979

80-
def __deepcopy__(self, memodict={}):
80+
def __deepcopy__(self, memodict={}) -> "Dictable": # noqa: MAN001
8181
return self.__copy__()
8282

8383
@abstractmethod
84-
def to_dict(self):
84+
def to_dict(self) -> Mapping[str, Any]:
8585
"""
8686
Return a dictionary representation of the class.
8787
"""
8888

8989
return {} # pragma: no cover (abc)
9090

91-
def __eq__(self, other) -> bool:
91+
def __eq__(self, other) -> bool: # noqa: MAN001
9292
if isinstance(other, self.__class__):
9393
return is_match_with(other.to_dict(), self.to_dict())
9494

mh_utils/cef_parser/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
import datetime
7272
import re
7373
from pprint import pformat
74-
from typing import Dict, Iterable, List, Optional, Sequence, Type, Union
74+
from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Type, Union
7575

7676
# 3rd party
7777
import attr
78-
import lxml.objectify # type: ignore
78+
import lxml.objectify # type: ignore[import-untyped]
7979
from attr_utils.docstrings import add_attrs_doc
8080
from attr_utils.serialise import serde
8181
from chemistry_tools.formulae import Formula
@@ -141,7 +141,7 @@ def __init__(
141141
else:
142142
raise TypeError(f"'matches' must be a dictionary, not {type(matches)}")
143143

144-
def to_dict(self):
144+
def to_dict(self) -> Mapping[str, Any]:
145145
"""
146146
Return a dictionary representation of the class.
147147
"""
@@ -321,7 +321,7 @@ def __init__(
321321
"rt_ranges",
322322
]
323323

324-
def to_dict(self):
324+
def to_dict(self) -> Mapping[str, Any]:
325325
"""
326326
Return a dictionary representation of the class.
327327
"""
@@ -383,10 +383,10 @@ class RTRange:
383383
"""
384384

385385
#: The start time in minutes
386-
start: datetime.timedelta = attr.ib(converter=make_timedelta, default=0.0) # type: ignore
386+
start: datetime.timedelta = attr.ib(converter=make_timedelta, default=0.0) # type: ignore[assignment]
387387

388388
#: The end time in minutes
389-
end: datetime.timedelta = attr.ib(converter=make_timedelta, default=0.0) # type: ignore
389+
end: datetime.timedelta = attr.ib(converter=make_timedelta, default=0.0) # type: ignore[assignment]
390390

391391
@classmethod
392392
def from_xml(cls, element: lxml.objectify.ObjectifiedElement) -> "RTRange":
@@ -417,10 +417,10 @@ class Flag(str):
417417
__slots__ = ("severity", )
418418
severity: int
419419

420-
def __copy__(self):
420+
def __copy__(self) -> "Flag":
421421
return Flag(str(self), self.severity)
422422

423-
def __deepcopy__(self, memodict={}):
423+
def __deepcopy__(self, memodict={}) -> "Flag": # noqa: MAN001
424424
return Flag(str(self), int(self.severity))
425425

426426
def __new__(cls: Type["Flag"], string: str, severity: int) -> "Flag": # noqa: D102
@@ -429,13 +429,13 @@ def __new__(cls: Type["Flag"], string: str, severity: int) -> "Flag": # noqa: D
429429

430430
return obj
431431

432-
def __eq__(self, other) -> bool:
432+
def __eq__(self, other) -> bool: # noqa: MAN001
433433
if isinstance(other, Flag):
434434
return str(self) == str(other) and self.severity == other.severity
435435
else:
436436
return super().__eq__(other)
437437

438-
def __ne__(self, other) -> bool:
438+
def __ne__(self, other) -> bool: # noqa: MAN001
439439
return NotImplemented
440440

441441
def __repr__(self) -> str:
@@ -465,16 +465,16 @@ class Score(float):
465465

466466
flag: Flag
467467

468-
def __copy__(self):
468+
def __copy__(self) -> "Score":
469469
return Score(float(self), str(self.flag), self.flag.severity)
470470

471-
def __deepcopy__(self, memodict={}):
471+
def __deepcopy__(self, memodict={}) -> "Score": # noqa: MAN001
472472
return Score(float(self), str(self.flag), int(self.flag.severity))
473473

474-
def __init__(self, score, flag_string: str = '', flag_severity: int = 0):
474+
def __init__(self, score, flag_string: str = '', flag_severity: int = 0): # noqa: MAN001
475475
float.__init__(float(score))
476476

477-
def __new__(cls, score, flag_string: str = '', flag_severity: int = 0) -> "Score": # noqa: D102
477+
def __new__(cls, score, flag_string: str = '', flag_severity: int = 0) -> "Score": # noqa: D102,MAN001
478478
obj = super().__new__(cls, float(score))
479479
obj.flag = Flag(flag_string, flag_severity)
480480

@@ -497,13 +497,13 @@ def __str__(self) -> str:
497497

498498
return str(float(self))
499499

500-
def __eq__(self, other) -> bool:
500+
def __eq__(self, other) -> bool: # noqa: MAN001
501501
if isinstance(other, Score):
502502
return float(self) == float(other) and self.flag == other.flag
503503
else:
504504
return super().__eq__(other)
505505

506-
def __ne__(self, other) -> bool:
506+
def __ne__(self, other) -> bool: # noqa: MAN001
507507
return NotImplemented
508508

509509

@@ -562,7 +562,7 @@ class LocationDict(TypedDict, total=False):
562562

563563
class _CompoundStrPPrinter(FancyPrinter):
564564

565-
def _repr(self, object, context, level): # noqa: A002 # pylint: disable=redefined-builtin
565+
def _repr(self, object, context, level) -> str: # noqa: MAN001,A002 # pylint: disable=redefined-builtin
566566
if isinstance(object, (Molecule, Formula)):
567567
self._readable = True
568568
self._recursive = False
@@ -619,7 +619,7 @@ def __init__(
619619
else:
620620
self.spectra = []
621621

622-
def to_dict(self):
622+
def to_dict(self) -> Mapping[str, Any]:
623623
"""
624624
Return a dictionary representation of the class.
625625
"""

mh_utils/csv_parser/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from typing import Iterable
3838

3939
# 3rd party
40-
import pandas # type: ignore
40+
import pandas
4141
import sdjson
4242
from domdf_python_tools.paths import PathPlus
4343
from domdf_python_tools.typing import PathLike
@@ -68,7 +68,7 @@ def __init__(self, raw_results_dir: PathLike, json_results_dir: PathLike, csv_re
6868
self.csv_results_dir = PathPlus(csv_results_dir)
6969
self.csv_results_dir.maybe_make(parents=True)
7070

71-
def parse_for_directory(self, directory: PathLike):
71+
def parse_for_directory(self, directory: PathLike) -> None:
7272
"""
7373
Convert the "CSV Results.csv" file in the given directory to CSV and JSON.
7474
@@ -86,7 +86,7 @@ def parse_for_directory(self, directory: PathLike):
8686

8787
parse_masshunter_csv(infile, csv_outfile, json_outfile)
8888

89-
def parse_directory_list(self, directory_list: Iterable[PathLike]):
89+
def parse_directory_list(self, directory_list: Iterable[PathLike]) -> None:
9090
"""
9191
Runs :meth:`.~ResultsParser.parse_for_directory` for each directory in ``directory_list``.
9292
@@ -98,7 +98,7 @@ def parse_directory_list(self, directory_list: Iterable[PathLike]):
9898
self.parse_for_directory(directory)
9999

100100

101-
def parse_masshunter_csv(csv_file: PathLike, csv_outfile: PathLike, json_outfile: PathLike):
101+
def parse_masshunter_csv(csv_file: PathLike, csv_outfile: PathLike, json_outfile: PathLike) -> None:
102102
"""
103103
Parse CSV results files created by MassHunter.
104104
@@ -125,7 +125,7 @@ def parse_masshunter_csv(csv_file: PathLike, csv_outfile: PathLike, json_outfile
125125

126126
PathPlus(json_outfile).dump_json(
127127
samples,
128-
json_library=sdjson, # type: ignore
128+
json_library=sdjson, # type: ignore[arg-type]
129129
indent=2,
130130
)
131131
# TODO: https://github.com/python/mypy/issues/5018

0 commit comments

Comments
 (0)