-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdecorlib.py
More file actions
44 lines (42 loc) · 1.17 KB
/
decorlib.py
File metadata and controls
44 lines (42 loc) · 1.17 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
43
44
##
# .python.decorlib
##
"""
common decorators
"""
import os
import types
def propertydoc(ap):
"""
Helper function for extracting an `abstractproperty`'s real documentation.
"""
doc = ""
rstr = ""
if ap.fget:
ret = ap.fget.__annotations__.get('return')
if ret is not None:
rstr = " -> " + repr(ret)
if ap.fget.__doc__:
doc += os.linesep*2 + "GET::" + (os.linesep + ' '*4) + (os.linesep + ' '*4).join(
[x.strip() for x in ap.fget.__doc__.strip().split(os.linesep)]
)
if ap.fset and ap.fset.__doc__:
doc += os.linesep*2 + "SET::" + (os.linesep + ' '*4) + (os.linesep + ' '*4).join(
[x.strip() for x in ap.fset.__doc__.strip().split(os.linesep)]
)
if ap.fdel and ap.fdel.__doc__:
doc += os.linesep*2 + "DELETE::" + (os.linesep + ' '*4) + (os.linesep + ' '*4).join(
[x.strip() for x in ap.fdel.__doc__.strip().split(os.linesep)]
)
ap.__doc__ = "<no documentation>" if not doc else (
"Abstract Property" + rstr + doc
)
return ap
class method(object):
__slots__ = ('callable',)
def __init__(self, callable):
self.callable = callable
def __get__(self, val, typ):
if val is None:
return self.callable
return types.MethodType(self.callable, val)