Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyright struggles with typing #63

Closed
marcoppenheimer opened this issue Jun 10, 2024 · 1 comment
Closed

Pyright struggles with typing #63

marcoppenheimer opened this issue Jun 10, 2024 · 1 comment

Comments

@marcoppenheimer
Copy link

marcoppenheimer commented Jun 10, 2024

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 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)
gtsystem added a commit that referenced this issue Jun 17, 2024
gtsystem added a commit that referenced this issue Jun 17, 2024
@gtsystem
Copy link
Owner

Hi, I hope this is fixed in lightkube==0.15.3. Can you check if everything is fine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants