Skip to content

Commit

Permalink
Add some more type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotwrobson committed Jan 25, 2025
1 parent 524a365 commit 80bcb4f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
41 changes: 21 additions & 20 deletions pooch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
temporary_file,
os_cache,
unique_file_name,
FilePath,
FilePathInput,
)
from .downloaders import DOIDownloader, choose_downloader, doi_to_repository

FilePath = Union[str, os.PathLike]
Actions = Literal["download", "fetch", "update"]


Expand All @@ -49,18 +50,18 @@ def __call__( # noqa: E704
) -> Any: ...


Processor = Callable[[str, Actions, "Pooch"], Any]
Processor = Callable[[str, Actions, Optional["Pooch"]], Any]


def retrieve(
url,
known_hash,
fname=None,
path=None,
processor=None,
downloader=None,
progressbar=False,
):
url: str,
known_hash: Optional[str] = None,
fname: Optional[str] = None,
path: Optional[FilePath] = None,
processor: Optional[Processor] = None,
downloader: Optional[Downloader] = None,
progressbar: bool = False,
) -> str:
"""
Download and cache a single file locally.
Expand Down Expand Up @@ -278,15 +279,15 @@ def retrieve(


def create(
path,
base_url,
version=None,
version_dev="master",
env=None,
registry=None,
urls=None,
retry_if_failed=0,
allow_updates=True,
path: FilePathInput,
base_url: str,
version: Optional[str] = None,
version_dev: str = "master",
env: Optional[str] = None,
registry: Optional[dict] = None,
urls: Optional[dict] = None,
retry_if_failed: int = 0,
allow_updates: Union[bool, str] = True,
):
"""
Create a :class:`~pooch.Pooch` with sensible defaults to fetch data files.
Expand Down Expand Up @@ -503,7 +504,7 @@ class Pooch:

def __init__(
self,
path: str,
path: FilePath,
base_url: str,
registry: Optional[dict[str, str]] = None,
urls: Optional[dict[str, str]] = None,
Expand Down
10 changes: 9 additions & 1 deletion pooch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
Misc utilities
"""

import logging
import os
import tempfile
Expand Down Expand Up @@ -198,7 +199,14 @@ def parse_url(url):
return {"protocol": protocol, "netloc": netloc, "path": path}


def cache_location(path, env=None, version=None):
from typing import Optional, Union

FilePath = Union[str, os.PathLike]
FilePathInput = Union[FilePath, list[FilePath], tuple[FilePath]]

def cache_location(
path: FilePathInput, env: Optional[str] = None, version: Optional[str] = None
) -> Path:
"""
Location of the cache given a base path and optional configuration.
Expand Down

0 comments on commit 80bcb4f

Please sign in to comment.