Skip to content

classproperty

Base classes

Name Children Inherits
Generic
typing
Abstract base class for generic types.

⋔ Inheritance diagram

graph TD
  94767997["descriptors.classproperty"]
  3481597255["typing.Generic"]
  2751680898["builtins.object"]
  3481597255 --> 94767997
  2751680898 --> 3481597255

🛈 DocStrings

Descriptor for class-level properties.

Source code in src/llmling/core/descriptors.py
class classproperty[ReturnT]:  # noqa: N801
    """Descriptor for class-level properties."""

    def __init__(self, method: Callable[[type], ReturnT] | None = None) -> None:
        self.method = method

    def __get__(self, instance: Any, cls: type | None = None) -> ReturnT:
        if cls is None:
            cls = type(instance)
        if self.method is None:
            msg = "No method defined"
            raise AttributeError(msg)
        return self.method(cls)

    def __set__(self, instance: Any, value: Any) -> None:
        msg = "Can't set class property"
        raise AttributeError(msg)

:fa-brands-github: Show source on GitHub