mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Improve hvac adapter types (#11659)
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
version = "2.1.*"
|
||||
upstream_repository = "https://github.com/hvac/hvac"
|
||||
requires = ["types-requests"]
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
from _typeshed import Incomplete
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
from typing import Any, Generic, TypeVar
|
||||
from typing_extensions import Self
|
||||
|
||||
class Adapter(metaclass=ABCMeta):
|
||||
from requests import Response, Session
|
||||
|
||||
_R = TypeVar("_R")
|
||||
|
||||
class Adapter(Generic[_R], metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def from_adapter(cls, adapter: Adapter) -> Self: ...
|
||||
def from_adapter(cls, adapter: Adapter[_R]) -> Self: ...
|
||||
base_uri: str
|
||||
token: str | None
|
||||
namespace: str | None
|
||||
session: bool
|
||||
session: Session
|
||||
allow_redirects: bool
|
||||
ignore_exceptions: bool
|
||||
strict_http: bool
|
||||
@@ -24,7 +27,7 @@ class Adapter(metaclass=ABCMeta):
|
||||
timeout: int = 30,
|
||||
proxies: Mapping[str, str] | None = None,
|
||||
allow_redirects: bool = True,
|
||||
session: Incomplete | None = None,
|
||||
session: Session | None = None,
|
||||
namespace: str | None = None,
|
||||
ignore_exceptions: bool = False,
|
||||
strict_http: bool = False,
|
||||
@@ -33,28 +36,30 @@ class Adapter(metaclass=ABCMeta):
|
||||
@staticmethod
|
||||
def urljoin(*args: object) -> str: ...
|
||||
def close(self) -> None: ...
|
||||
def get(self, url: str, **kwargs: Any): ...
|
||||
def post(self, url: str, **kwargs: Any): ...
|
||||
def put(self, url: str, **kwargs: Any): ...
|
||||
def delete(self, url: str, **kwargs: Any): ...
|
||||
def list(self, url: str, **kwargs: Any): ...
|
||||
def head(self, url: str, **kwargs: Any): ...
|
||||
def get(self, url: str, **kwargs: Any) -> _R: ...
|
||||
def post(self, url: str, **kwargs: Any) -> _R: ...
|
||||
def put(self, url: str, **kwargs: Any) -> _R: ...
|
||||
def delete(self, url: str, **kwargs: Any) -> _R: ...
|
||||
def list(self, url: str, **kwargs: Any) -> _R: ...
|
||||
def head(self, url: str, **kwargs: Any) -> _R: ...
|
||||
def login(self, url: str, use_token: bool = True, **kwargs: Any): ...
|
||||
@abstractmethod
|
||||
def get_login_token(self, response) -> str: ...
|
||||
def get_login_token(self, response: _R) -> str: ...
|
||||
@abstractmethod
|
||||
def request(
|
||||
self, method, url: str, headers: Mapping[str, str] | None = None, raise_exception: bool = True, **kwargs: Any
|
||||
): ...
|
||||
) -> _R: ...
|
||||
|
||||
class RawAdapter(Adapter):
|
||||
def get_login_token(self, response) -> str: ...
|
||||
class _GenericRawAdapter(Adapter[_R]):
|
||||
def get_login_token(self, response: _R) -> str: ...
|
||||
def request(
|
||||
self, method: str, url: str, headers: Mapping[str, str] | None = None, raise_exception: bool = True, **kwargs: Any
|
||||
): ...
|
||||
) -> _R: ...
|
||||
|
||||
class JSONAdapter(RawAdapter):
|
||||
def get_login_token(self, response) -> str: ...
|
||||
def request(self, *args: Any, **kwargs: Any): ...
|
||||
class RawAdapter(_GenericRawAdapter[Response]): ...
|
||||
|
||||
class JSONAdapter(_GenericRawAdapter[Response | dict[Any, Any]]):
|
||||
def get_login_token(self, response: Response | dict[Any, Any]) -> str: ...
|
||||
def request(self, *args: Any, **kwargs: Any) -> Response | dict[Any, Any]: ...
|
||||
|
||||
Request = RawAdapter
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections.abc import Sequence
|
||||
from logging import Logger
|
||||
from typing import Any
|
||||
|
||||
from hvac.adapters import Adapter
|
||||
from hvac.api.vault_api_base import VaultApiBase
|
||||
@@ -9,12 +10,12 @@ logger: Logger
|
||||
|
||||
class VaultApiCategory(VaultApiBase, metaclass=ABCMeta):
|
||||
implemented_class_names: Sequence[str]
|
||||
def __init__(self, adapter: Adapter) -> None: ...
|
||||
def __init__(self, adapter: Adapter[Any]) -> None: ...
|
||||
def __getattr__(self, item): ...
|
||||
@property
|
||||
def adapter(self) -> Adapter: ...
|
||||
def adapter(self) -> Adapter[Any]: ...
|
||||
@adapter.setter
|
||||
def adapter(self, adapter: Adapter) -> None: ...
|
||||
def adapter(self, adapter: Adapter[Any]) -> None: ...
|
||||
@property
|
||||
@abstractmethod
|
||||
def implemented_classes(self): ...
|
||||
|
||||
@@ -16,15 +16,15 @@ class Client:
|
||||
proxies: dict[str, str] | None = None,
|
||||
allow_redirects: bool = True,
|
||||
session: Incomplete | None = None,
|
||||
adapter: type[Adapter] = ...,
|
||||
adapter: type[Adapter[Any]] = ...,
|
||||
namespace: Incomplete | None = None,
|
||||
**kwargs: Any,
|
||||
) -> None: ...
|
||||
def __getattr__(self, name: str) -> Any: ...
|
||||
@property
|
||||
def adapter(self) -> Adapter: ...
|
||||
def adapter(self) -> Adapter[Any]: ...
|
||||
@adapter.setter
|
||||
def adapter(self, adapter: Adapter) -> None: ...
|
||||
def adapter(self, adapter: Adapter[Any]) -> None: ...
|
||||
@property
|
||||
def url(self) -> str: ...
|
||||
@url.setter
|
||||
|
||||
Reference in New Issue
Block a user