[PATCH 09/14] Type from_git_config keyword arguments
Tamir Duberstein <[email protected]>
| Newsgroups | org.kernel.linux.tools |
|---|---|
| Message-ID | <[email protected]> |
Define a TypedDict for LoreNode constructor keyword arguments and annotate from_git_config with an unpacked kwargs signature. This removes the constructor-call type suppressions while keeping git-config defaults and caller overrides unchanged. Signed-off-by: Tamir Duberstein <[email protected]> --- pyproject.toml | 1 + src/liblore/node.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 37c85a7..387757c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ dev = [ "ruff", "ty", "types-requests", + "typing-extensions", ] [tool.pytest.ini_options] diff --git a/src/liblore/node.py b/src/liblore/node.py index 1b0463e..4835169 100644 --- a/src/liblore/node.py +++ b/src/liblore/node.py @@ -17,6 +17,7 @@ import types import urllib.parse from datetime import datetime, timezone from email.message import EmailMessage +from typing import TYPE_CHECKING, TypedDict import requests @@ -29,6 +30,19 @@ from liblore.utils import ( logger = logging.getLogger(__name__) +if TYPE_CHECKING: + from typing_extensions import Unpack + + +class _LoreNodeInitKwargs(TypedDict, total=False): + fallback_urls: list[str] | None + auto_probe: bool + probe_timeout: float + probe_ttl: int + add_auth_headers: bool + cache_dir: str + cache_ttl: int + def _get_config_from_git( regexp: str, @@ -212,7 +226,7 @@ class LoreNode: def from_git_config( cls, url: str = 'https://lore.kernel.org/all', - **kwargs: object, + **kwargs: Unpack[_LoreNodeInitKwargs], ) -> LoreNode: """Create a :class:`LoreNode` using settings from git config. @@ -319,7 +333,7 @@ class LoreNode: except ValueError: pass - node = cls(url, **kwargs) # type: ignore[arg-type] # ty:ignore[invalid-argument-type] + node = cls(url, **kwargs) val = gitcfg.get('useragentplus') if isinstance(val, str) and val: -- 2.53.0