This commit is contained in:
itamar 2026-04-10 00:21:44 +02:00
commit 8eb63a0625
Signed by: itamar
SSH key fingerprint: SHA256:Dv6UzB9hN8q8FUgMR/7X3DTFpE/vSB2m05+KNnxM4B0
6 changed files with 1020 additions and 0 deletions

30
lib/classmethod.py Normal file
View file

@ -0,0 +1,30 @@
from __future__ import annotations
class Classmethod:
def __init__(self, func):
self.func = func
self._attribute_name: str = getattr(func, "__name__", "<classmethod>")
def __set_name__(self, owner, name: str):
self._attribute_name = name
def __get__(self, instance, owner=None):
if owner is None:
owner = type(instance)
func = self.func
attr = self._attribute_name
def bound(*args, **kwargs):
return func(owner, *args, **kwargs)
bound.__name__ = attr
bound.__qualname__ = f"{owner.__qualname__}.{attr}"
return bound
def __set__(self, instance, value):
raise AttributeError("Classmethod reassigend")
def __repr__(self) -> str:
return f"Classmethod({self.func!r})"
Classmthod = Classmethod