Skip to content

Commit bc449e4

Browse files
committed
typ: Update type annotations
1 parent afb3587 commit bc449e4

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

templateflow/client.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __getattr__(self, name: str):
6060
msg = f"'{self.__class__.__name__}' object has no attribute '{name}'"
6161
raise AttributeError(msg) from None
6262

63-
def ls(self, template, **kwargs):
63+
def ls(self, template, **kwargs) -> list[Path]:
6464
"""
6565
List files pertaining to one or more templates.
6666
@@ -124,7 +124,7 @@ def ls(self, template, **kwargs):
124124
)
125125
]
126126

127-
def get(self, template, raise_empty=False, **kwargs):
127+
def get(self, template, raise_empty=False, **kwargs) -> list[Path]:
128128
"""
129129
Pull files pertaining to one or more templates down.
130130
@@ -228,7 +228,7 @@ def get(self, template, raise_empty=False, **kwargs):
228228
return out_file[0]
229229
return out_file
230230

231-
def templates(self, **kwargs):
231+
def templates(self, **kwargs) -> list[str]:
232232
"""
233233
Return a list of available templates.
234234
@@ -260,7 +260,7 @@ def templates(self, **kwargs):
260260
"""
261261
return sorted(self.get_templates(**kwargs))
262262

263-
def get_metadata(self, template):
263+
def get_metadata(self, template) -> dict[str, str]:
264264
"""
265265
Fetch one file from one template.
266266
@@ -288,7 +288,7 @@ def get_metadata(self, template):
288288
_datalad_get(filepath)
289289
return loads(filepath.read_text())
290290

291-
def get_citations(self, template, bibtex=False):
291+
def get_citations(self, template, bibtex=False) -> list[str]:
292292
"""
293293
Fetch template citations
294294
@@ -308,13 +308,10 @@ def get_citations(self, template, bibtex=False):
308308
if not bibtex:
309309
return refs
310310

311-
return [
312-
_to_bibtex(ref, template, idx, self.cache.config.timeout).rstrip()
313-
for idx, ref in enumerate(refs, 1)
314-
]
311+
return [_to_bibtex(ref, template, self.cache.config.timeout).rstrip() for ref in refs]
315312

316313

317-
def _datalad_get(config: CacheConfig, filepath: Path):
314+
def _datalad_get(config: CacheConfig, filepath: Path) -> None:
318315
if not filepath:
319316
return
320317

@@ -331,7 +328,7 @@ def _datalad_get(config: CacheConfig, filepath: Path):
331328
raise
332329

333330

334-
def _s3_get(config: CacheConfig, filepath: Path):
331+
def _s3_get(config: CacheConfig, filepath: Path) -> None:
335332
from sys import stderr
336333
from urllib.parse import quote
337334

@@ -365,7 +362,7 @@ def _s3_get(config: CacheConfig, filepath: Path):
365362
raise RuntimeError('ERROR, something went wrong')
366363

367364

368-
def _to_bibtex(doi, template, idx, timeout):
365+
def _to_bibtex(doi: str, template: str, timeout: float) -> str:
369366
if 'doi.org' not in doi:
370367
return doi
371368

templateflow/conf/cache.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
@cache
22-
def _have_datalad():
22+
def _have_datalad() -> bool:
2323
import importlib.util
2424

2525
return importlib.util.find_spec('datalad') is not None
@@ -34,7 +34,7 @@ class CacheConfig:
3434
autoupdate: bool = field(default_factory=env_to_bool('TEMPLATEFLOW_AUTOUPDATE', True))
3535
timeout: int = field(default=10)
3636

37-
def __post_init__(self):
37+
def __post_init__(self) -> None:
3838
global STACKLEVEL
3939
if self.use_datalad and not _have_datalad():
4040
self.use_datalad = False
@@ -46,7 +46,7 @@ def __post_init__(self):
4646
class S3Manager:
4747
s3_root: str
4848

49-
def install(self, path: Path, overwrite: bool, timeout: int):
49+
def install(self, path: Path, overwrite: bool, timeout: int) -> None:
5050
from ._s3 import update
5151

5252
update(path, local=True, overwrite=overwrite, silent=True, timeout=timeout)
@@ -56,7 +56,7 @@ def update(self, path: Path, local: bool, overwrite: bool, silent: bool, timeout
5656

5757
return _update_s3(path, local=local, overwrite=overwrite, silent=silent, timeout=timeout)
5858

59-
def wipe(self, path: Path):
59+
def wipe(self, path: Path) -> None:
6060
from shutil import rmtree
6161

6262
def _onerror(func, path, excinfo):
@@ -72,7 +72,7 @@ def _onerror(func, path, excinfo):
7272
class DataladManager:
7373
source: str
7474

75-
def install(self, path: Path, overwrite: bool, timeout: int):
75+
def install(self, path: Path, overwrite: bool, timeout: int) -> None:
7676
from datalad.api import install
7777

7878
install(path=path, source=self.source, recursive=True)
@@ -91,7 +91,7 @@ def update(self, path: Path, local: bool, overwrite: bool, silent: bool, timeout
9191
return False
9292
return True
9393

94-
def wipe(self, path: Path):
94+
def wipe(self, path: Path) -> None:
9595
print('TemplateFlow is configured in DataLad mode, wipe() has no effect')
9696

9797

@@ -101,7 +101,7 @@ class TemplateFlowCache:
101101
precached: bool = field(init=False)
102102
manager: DataladManager | S3Manager = field(init=False)
103103

104-
def __post_init__(self):
104+
def __post_init__(self) -> None:
105105
self.manager = (
106106
DataladManager(self.config.origin)
107107
if self.config.use_datalad
@@ -133,13 +133,13 @@ def layout(self) -> BIDSLayout:
133133
),
134134
)
135135

136-
def ensure(self):
136+
def ensure(self) -> None:
137137
if not self.cached:
138138
self.manager.install(
139139
self.config.root, overwrite=self.config.autoupdate, timeout=self.config.timeout
140140
)
141141

142-
def update(self, local: bool = False, overwrite: bool = True, silent: bool = False):
142+
def update(self, local: bool = False, overwrite: bool = True, silent: bool = False) -> bool:
143143
if self.manager.update(
144144
self.config.root,
145145
local=local,
@@ -151,6 +151,6 @@ def update(self, local: bool = False, overwrite: bool = True, silent: bool = Fal
151151
return True
152152
return False
153153

154-
def wipe(self):
154+
def wipe(self) -> None:
155155
self.__dict__.pop('layout', None) # Uncache property
156156
self.manager.wipe(self.config.root)

0 commit comments

Comments
 (0)