-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetterTypes.py
More file actions
42 lines (24 loc) · 1.01 KB
/
BetterTypes.py
File metadata and controls
42 lines (24 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Descriptors
def Raise(ErrorType=Exception,*args): raise ErrorType(*args)
class ClassProperty(property):
fget = lambda *args:Raise(AttributeError,"unreadable attribute")
def __init__(self, fget=None, doc=None):
if fget: self.fget = fget
self.__doc__ = doc if doc else fget.__doc__
def __get__(self, inst, cls=None):
return self.fget(cls or type(inst))
class TestClass:
testVal = 5
@ClassProperty
def testGet(cls):return cls.testVal
print(TestClass.testVal)
print(TestClass.testGet)
TestClass.testGet = 54
from typing import Callable,TypeVar,Generic
Return = TypeVar('Return')
class Action(Generic[Return]):
def __init__(self, actionFunc:Callable[...,Return], *args,**kwds):
self.computeFunc,self.args,self.kwds = actionFunc,args,kwds
def compute(self):return self.computeFunc(*self.args,**self.kwds)
def __call__(self):return self.compute()