I've had a lot of issues with the typing inference with pyright. I want to confirm I'm not 'doing it wrong'.
How can I type-hint Pod from Client.get(), and not the generic NamespacedResource or GlobalResource?
Example File
"""Docstring."""
from functools import cached_property
from lightkube.config.kubeconfig import DEFAULT_KUBECONFIG, KubeConfig
from lightkube.core.client import Client
from lightkube.resources.core_v1 import Pod
class K8s:
"""Docstring."""
def __init__(self):
pass
@cached_property
def client(self) -> Client:
"""Docstring."""
return Client(
field_manager="app",
namespace="namespace",
config=KubeConfig.from_env(DEFAULT_KUBECONFIG),
)
@property
def pod(self) -> Pod:
"""Docstring."""
return self.client.get(
res=Pod,
name="pod",
)
Then you can run pyright --verbose file.py and you'll get:
/home/marc/file.py
/home/marc/file.py:28:16 - error: Expression of type "NamespacedResource" is incompatible with return type "Pod"
"NamespacedResource" is incompatible with "Pod" (reportReturnType)
Issue
I've had a lot of issues with the typing inference with pyright. I want to confirm I'm not 'doing it wrong'. How can I type-hint
Pod
fromClient.get()
, and not the genericNamespacedResource
orGlobalResource
?Example File
Then you can run
pyright --verbose file.py
and you'll get: