Created
May 12, 2020 20:41
-
-
Save llllllllll/ba7e0d93b892283b1fde25ea47e73983 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WithLazyDoc: | |
def __init__(self, get_doc, f): | |
self._get_doc = get_doc | |
self._f = f | |
@property | |
def __wrapped__(self): | |
return self._f | |
@property | |
def __signature__(self): | |
return inspect.signature(self._f) | |
@property | |
def __doc__(self): | |
return self._get_doc() | |
def __call__(self, *args, **kwargs): | |
return self._f(*args, **kwargs) | |
class C: | |
def m(self, a, b): | |
pass | |
def lazy_doc(): | |
lazy_doc.called += 1 | |
return f'lazy doc {lazy_doc.called}' | |
lazy_doc.called = 0 | |
C.m = WithLazyDoc(lazy_doc, C.m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [23]: C.m? | |
Signature: C.m(self, a, b) | |
Call signature: C.m(*args, **kwargs) | |
Type: WithLazyDoc | |
String form: <__main__.WithLazyDoc object at 0x7feb0c20ad90> | |
File: ~/quantopian/qexec/<ipython-input-22-4a8288420109> | |
Docstring: lazy doc 1 | |
In [24]: C.m? | |
Signature: C.m(self, a, b) | |
Call signature: C.m(*args, **kwargs) | |
Type: WithLazyDoc | |
String form: <__main__.WithLazyDoc object at 0x7feb0c20ad90> | |
File: ~/quantopian/qexec/<ipython-input-22-4a8288420109> | |
Docstring: lazy doc 2 | |
In [25]: C.m? | |
Signature: C.m(self, a, b) | |
Call signature: C.m(*args, **kwargs) | |
Type: WithLazyDoc | |
String form: <__main__.WithLazyDoc object at 0x7feb0c20ad90> | |
File: ~/quantopian/qexec/<ipython-input-22-4a8288420109> | |
Docstring: lazy doc 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment