Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address some mypy type hinting issues #2314

Merged
merged 17 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/quacc/atoms/slabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def make_slabs_from_bulk(
# Add slab to list
slabs_with_props.append(slab)

final_slabs = []
final_slabs: list[Atoms] = []
if not slabs_with_props:
return final_slabs

Expand All @@ -224,7 +224,7 @@ def make_adsorbate_structures(
atoms: Atoms,
adsorbate: Atoms,
min_distance: float = 2.0,
modes: list[str] | None = None,
modes: list[Literal["ontop", "bridge", "hollow", "subsurface"]] | None = None,
allowed_surface_symbols: list[str] | None = None,
allowed_surface_indices: list[int] | None = None,
ads_site_finder_kwargs: AdsSiteFinderKwargs | None = None,
Expand Down Expand Up @@ -282,7 +282,7 @@ def make_adsorbate_structures(
msg = "Cannot specify both modes and find_ads_sites_kwargs['positions']"
raise ValueError(msg)
find_ads_sites_kwargs["distance"] = min_distance
find_ads_sites_kwargs["positions"] = [mode.lower() for mode in modes]
find_ads_sites_kwargs["positions"] = modes

# Check the provided surface indices are reasonable
atom_indices = [atom.index for atom in atoms]
Expand Down
2 changes: 1 addition & 1 deletion src/quacc/calculators/espresso/espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def read_results(self, directory: Path | str) -> dict[str, Any]:
"""
results = {}
if self.binary == "pw":
atoms = read(directory / self.outputname, format="espresso-out")
atoms = read(Path(directory) / self.outputname, format="espresso-out")
results = dict(atoms.calc.properties())
elif self.binary in ["ph", "phcg"]:
with Path(directory, self.outputname).open() as fd:
Expand Down
2 changes: 1 addition & 1 deletion src/quacc/calculators/vasp/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _cleanup_params(self) -> None:

def _run(
self,
command: list[str] | None = None,
command: str | None = None,
out: Path | str | None = None,
directory: Path | str | None = None,
) -> int:
Expand Down
1 change: 0 additions & 1 deletion src/quacc/calculators/vasp/vasp_custodian.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def run_custodian(
)

# Handlers for VASP
handlers = []
handlers_dict = {
"VaspErrorHandler": VaspErrorHandler(vtst_fixes=vtst_fixes),
"FrozenJobErrorHandler": FrozenJobErrorHandler(),
Expand Down
3 changes: 3 additions & 0 deletions src/quacc/recipes/gulp/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
keyword_defaults += ["conv"]
keyword_defaults = [k for k in keyword_defaults if k not in ["gwolf", "conp"]]

if option_defaults is None:
option_defaults = []

Check warning on line 83 in src/quacc/recipes/gulp/_base.py

View check run for this annotation

Codecov / codecov/patch

src/quacc/recipes/gulp/_base.py#L83

Added line #L83 was not covered by tests

option_defaults += [
(
f"output cif {GEOM_FILE_PBC}"
Expand Down
5 changes: 3 additions & 2 deletions src/quacc/recipes/vasp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@ def non_scf_job(
Dictionary of results from [quacc.schemas.vasp.vasp_summarize_run][].
See the type-hint for the data structure.
"""
vasprun_path = zpath(Path(prev_dir, "vasprun.xml"))

vasprun_path = zpath(str(Path(prev_dir, "vasprun.xml")))
vasprun = Vasprun(vasprun_path)

prior_nbands = vasprun.parameters["NBANDS"]
calc_defaults = {
calc_defaults: dict[str, Any] = {
"icharg": 11,
"kspacing": None,
"lcharg": False,
Expand Down
7 changes: 6 additions & 1 deletion src/quacc/runners/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def calc_cleanup(
symlink_path.unlink(missing_ok=True)


def terminate(tmpdir: Path | str, exception: Exception) -> Exception:
def terminate(tmpdir: Path | str, exception: Exception) -> None:
"""
Terminate a calculation and move files to a failed directory.

Expand All @@ -149,11 +149,16 @@ def terminate(tmpdir: Path | str, exception: Exception) -> Exception:
exception
The exception that caused the calculation to fail.

Returns
-------
None

Raises
-------
Exception
The exception that caused the calculation to fail.
"""
tmpdir = Path(tmpdir)
settings = get_settings()
job_failed_dir = tmpdir.with_name(tmpdir.name.replace("tmp-", "failed-"))
tmpdir.rename(job_failed_dir)
Expand Down
4 changes: 2 additions & 2 deletions src/quacc/schemas/_aliases/cclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class Attributes(TypedDict, total=False):
natom: int
nbasis: int
nmo: int
nmrtensors: dict[int, dict[NDArray]]
nmrcouplingtensors: dict[int, dict[NDArray]]
nmrtensors: dict[int, dict[str, NDArray]]
nmrcouplingtensors: dict[int, dict[str, NDArray]]
nocoeffs: NDArray
nooccnos: NDArray
nsocoeffs: list[NDArray]
Expand Down
4 changes: 2 additions & 2 deletions src/quacc/schemas/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def vasp_summarize_run(
raise RuntimeError(
f"VASP calculation did not converge. Will not store task data. Refer to {directory}"
)

initial_atoms = read(zpath(directory / "POSCAR"))
poscar_path = directory / "POSCAR"
initial_atoms = read(zpath(str(poscar_path)))
base_task_doc = summarize_run(
final_atoms, initial_atoms, move_magmoms=move_magmoms, store=None
)
Expand Down
3 changes: 2 additions & 1 deletion src/quacc/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def check_logfile(logfile: str | Path, check_str: str) -> bool:
bool
True if the string is found in the logfile, False otherwise.
"""
zlog = Path(zpath(Path(logfile).expanduser()))
logfile_path = Path(logfile).expanduser()
zlog = Path(zpath(str(logfile_path)))
with zopen(zlog, "r") as f:
for line in f:
clean_line = line if isinstance(line, str) else line.decode("utf-8")
Expand Down
4 changes: 2 additions & 2 deletions src/quacc/utils/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def merge_list_params(
Merged list
"""
merged_list = []
lists = [list_ for list_ in lists if list_]
for list_ in lists:
lists_ = [list_ for list_ in lists if list_]
for list_ in lists_:
for item in list_:
item_ = item
if case_insensitive:
Expand Down
2 changes: 1 addition & 1 deletion src/quacc/wflow_tools/job_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def map_partitioned_lists(
func: Callable,
num_partitions: int,
unmapped_kwargs: dict[str, Any] | None = None,
**mapped_kwargs: dict[str, list[list[Any]]],
**mapped_kwargs: list[list[Any]],
) -> list[Any]:
"""
Given list-of-lists parameters (say a list of batches that we want to map over),
Expand Down
Loading