Skip to content

Commit fc3f524

Browse files
committed
mypy
1 parent 8979b8a commit fc3f524

File tree

7 files changed

+34
-23
lines changed

7 files changed

+34
-23
lines changed

autotest/test_misc.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ def test_set_env():
4343
assert environ.get(key) is None
4444

4545

46-
_repos_path = environ.get("REPOS_PATH")
47-
if _repos_path is None:
48-
_repos_path = Path(__file__).parent.parent.parent.parent
49-
_repos_path = Path(_repos_path).expanduser().absolute()
46+
_repos_path_str = environ.get("REPOS_PATH")
47+
if _repos_path_str is None:
48+
_repos_path: Path = Path(__file__).parent.parent.parent.parent
49+
else:
50+
_repos_path = Path(_repos_path_str).expanduser().absolute()
5051
_testmodels_repo_path = _repos_path / "modflow6-testmodels"
5152
_testmodels_repo_paths_mf6 = sorted((_testmodels_repo_path / "mf6").glob("test*"))
5253
_testmodels_repo_paths_mf5to6 = sorted((_testmodels_repo_path / "mf5to6").glob("test*"))
@@ -132,7 +133,7 @@ def get_expected_model_dirs(path, pattern="mfsim.nam") -> list[Path]:
132133

133134

134135
def get_expected_namefiles(path, pattern="mfsim.nam") -> list[Path]:
135-
folders = []
136+
folders: list[Path] = []
136137
for root, dirs, _ in os.walk(path):
137138
for d in dirs:
138139
p = Path(root) / d

autotest/test_snapshots.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from _pytest.config import ExitCode
77

88
proj_root = Path(__file__).parents[1]
9-
module_path = Path(inspect.getmodulename(__file__))
9+
_module_name = inspect.getmodulename(__file__)
10+
assert _module_name is not None
11+
module_path = Path(_module_name)
1012
snapshot_array = np.array([1.1, 2.2, 3.3])
1113
snapshots_path = proj_root / "autotest" / "__snapshots__"
1214

autotest/test_zip.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shutil
33
import sys
44
import zipfile
5+
from collections.abc import Generator
56
from pathlib import Path
67
from pprint import pprint
78
from shutil import which
@@ -15,7 +16,9 @@
1516

1617
ext, _ = get_suffixes(sys.platform)
1718
exe_stem = "pytest"
18-
exe_path = Path(which(exe_stem))
19+
_exe_which = which(exe_stem)
20+
assert _exe_which is not None, f"{exe_stem} not found in PATH"
21+
exe_path = Path(_exe_which)
1922
exe_name = f"{exe_stem}{ext}"
2023

2124

@@ -38,7 +41,7 @@ def test_compressall(function_tmpdir):
3841

3942

4043
@pytest.fixture(scope="module")
41-
def empty_archive(module_tmpdir) -> Path:
44+
def empty_archive(module_tmpdir) -> Generator[Path, None, None]:
4245
# https://stackoverflow.com/a/25195628/6514033
4346
data = b"PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" # noqa: E501
4447
path = module_tmpdir / "empty.zip"
@@ -53,7 +56,7 @@ def test_extractall_empty(empty_archive, function_tmpdir):
5356

5457

5558
@pytest.fixture(scope="module")
56-
def archive(module_tmpdir) -> Path:
59+
def archive(module_tmpdir) -> Generator[Path, None, None]:
5760
zip_path = module_tmpdir / "nonempty.zip"
5861
shutil.copy(exe_path, module_tmpdir)
5962
with set_dir(module_tmpdir):

modflow_devtools/make_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
action="store_true",
7575
help=(
7676
"Generate separate files (registry.toml, models.toml, examples.toml) "
77-
"for 1.x compatibility. Default is consolidated.",
77+
"for 1.x compatibility. Default is consolidated."
7878
),
7979
)
8080
parser.add_argument(

modflow_devtools/models/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class LocalRegistry(Registry):
6464

6565
def __init__(self) -> None:
6666
# Initialize Pydantic parent with empty data (no meta for local registries)
67-
super().__init__(meta=None, files={}, models={}, examples={})
67+
super().__init__(_meta=None, files={}, models={}, examples={})
6868
# Initialize non-Pydantic tracking variable
6969
self._paths = set()
7070

@@ -139,7 +139,9 @@ def copy_to(
139139
return None
140140

141141
# Get actual file paths from FileEntry objects
142-
file_paths = [self.files[name].path for name in file_names]
142+
file_paths = [
143+
p for name in file_names if (p := self.files[name].path) is not None
144+
]
143145

144146
# create the workspace if needed
145147
workspace = Path(workspace).expanduser().absolute()
@@ -203,7 +205,7 @@ def __init__(
203205
retries: int = 3,
204206
):
205207
# Initialize Pydantic parent with empty data (will be populated by _load())
206-
super().__init__(meta=None, files={}, models={}, examples={})
208+
super().__init__(_meta=None, files={}, models={}, examples={})
207209

208210
# Initialize non-Pydantic instance variables
209211
self._registry_path = Path(__file__).parent.parent / "registry"
@@ -530,10 +532,10 @@ def index(
530532
models_file_path = output_dir / PoochRegistry.models_file_name
531533
examples_file_path = output_dir / PoochRegistry.examples_file_name
532534

533-
with registry_file_path.open("ab+") as registry_file:
535+
with registry_file_path.open("ab+") as f:
534536
tomli_w.dump(
535537
remap(dict(sorted(files.items())), visit=drop_none_or_empty),
536-
registry_file,
538+
f,
537539
)
538540

539541
with models_file_path.open("ab+") as models_file:
@@ -628,12 +630,12 @@ def get_examples() -> dict[str, list[str]]:
628630
return DEFAULT_REGISTRY.examples
629631

630632

631-
def get_models() -> dict[str, str]:
633+
def get_models() -> dict[str, list[str]]:
632634
"""Get a map of model names to input files."""
633635
return DEFAULT_REGISTRY.models
634636

635637

636-
def get_files() -> dict[str, dict[str, str]]:
638+
def get_files() -> dict[str, FileEntry]:
637639
"""
638640
Get a map of file names to URLs. Note that this mapping
639641
contains no information on which files belong to which

modflow_devtools/models/sync.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,21 @@ def get_sync_status(bootstrap_path: Path | str | None = None) -> dict:
176176
source_name = source_meta.name
177177
refs = source_meta.refs if source_meta.refs else []
178178

179+
cached_refs: list[str] = []
180+
missing_refs: list[str] = []
181+
179182
source_status = {
180183
"repo": source_meta.repo,
181184
"configured_refs": refs,
182-
"cached_refs": [],
183-
"missing_refs": [],
185+
"cached_refs": cached_refs,
186+
"missing_refs": missing_refs,
184187
}
185188

186189
for ref_name in refs:
187190
if (source_name, ref_name) in cached_registries:
188-
source_status["cached_refs"].append(ref_name)
191+
cached_refs.append(ref_name)
189192
else:
190-
source_status["missing_refs"].append(ref_name)
193+
missing_refs.append(ref_name)
191194

192195
status[source_name] = source_status
193196

scripts/update_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def update_docs_config(version: Version):
4343

4444
def update_version(
4545
timestamp: datetime = datetime.now(),
46-
version: Version = None,
46+
version: Version | None = None,
4747
):
4848
lock_path = Path(_version_txt_path.name + ".lock")
4949
lock = FileLock(lock_path)
@@ -52,7 +52,7 @@ def update_version(
5252
version = (
5353
version
5454
if version
55-
else Version(previous.major, previous.minor, previous.micro)
55+
else Version(f"{previous.major}.{previous.minor}.{previous.micro}")
5656
)
5757

5858
update_version_txt(version)

0 commit comments

Comments
 (0)