3 ms·
Ah, it's allowed to mutate a function's `__code__` attribute: https://github.com/sshirokov/pydvice/blob/abfa0c5f1dc55780a8c7bf8d391a71da5d263b2a/lib/pydvice.py
by olejorgenb 3y ago
Ah, it's allowed to mutate a function's `__code__` attribute:
https://github.com/sshirokov/pydvice/blob/abfa0c5f1dc55780a8c7bf8d391a71da5d263b2a/lib/pydvice.py#L186 https://github.com/sshirokov/pydvice/blob/abfa0c5f1dc55780a8...
- agumonkey 3y agonifty trick
- albertzeyer 3y agoWhy is this needed for this library?
- olejorgenb 3y agoBecause the library can "advice" an existing function without decorating that function. # Write a function >>> def there(): ... print "there", ... >>> there() there # Write a peice of 'before advice' to run before the function # New advice is activated by default >>> @pydvice.before(there) ... def hello(): ... print "Hello", ... # Note that active advice runs automatically on any function call >>> there() Hello there