Skip to content

Commit

Permalink
Fix type hint on sync api.get() (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Jan 22, 2025
1 parent d19b6c1 commit 947edfd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions kr8s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get( # type: ignore
as_object: type[APIObject] | None = None,
allow_unknown_type: bool = True,
**kwargs,
) -> Generator[APIObject]:
) -> Generator[objects.APIObject]:
yield from _run_sync(self.async_get)(
kind,
*names,
Expand All @@ -96,7 +96,7 @@ def watch( # type: ignore
label_selector: str | dict | None = None,
field_selector: str | dict | None = None,
since: str | None = None,
) -> Generator[tuple[str, APIObject]]:
) -> Generator[tuple[str, objects.APIObject]]:
yield from _run_sync(self.async_watch)(
kind,
namespace=namespace,
Expand Down
4 changes: 4 additions & 0 deletions kr8s/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
from .portforward import PortForward


class APIObject(APIObjectSyncMixin):
__doc__ = APIObjectSyncMixin.__doc__


class Binding(APIObjectSyncMixin, _Binding):
__doc__ = _Binding.__doc__

Expand Down
9 changes: 6 additions & 3 deletions kr8s/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,17 @@ async def test_async_get_returns_async_objects() -> None:


def test_sync_get_returns_sync_objects() -> None:
pods = kr8s.get("pods", namespace=kr8s.ALL)
assert list(pods)[0]._asyncio is False
pods = list(kr8s.get("pods", namespace=kr8s.ALL))
assert pods[0]._asyncio is False
pods[0].refresh()


def test_sync_api_returns_sync_objects():
api = kr8s.api()
pods = api.get("pods", namespace=kr8s.ALL)
assert next(pods)._asyncio is False
pod = next(pods)
assert pod._asyncio is False
pod.refresh()


async def test_api_names(example_pod_spec: dict, ns: str) -> None:
Expand Down

0 comments on commit 947edfd

Please sign in to comment.