push
This commit is contained in:
commit
8eb63a0625
6 changed files with 1020 additions and 0 deletions
30
lib/classmethod.py
Normal file
30
lib/classmethod.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue