Swanky Python: Python development using Emacs' SLIME mode for Common Lisp
codeberg.org2 pointsby sczi0 comments
>>> from packaging.version import Version
>>> Version("1.2.3") > Version("1.2.2")
True
>>> Version("2.0") > Version("1.2.2")
True def dec(f):
def wraps():
return f() + 2
return wraps
@dec
def reload_me():
return 1
Then in b.py, from a import reload_me, change reload_me in a and slime-eval-defun it, and b is using the new version of reload_me. Basically for all (__module__, __qualname__) I am storing the function object, and all old versions of the function object. Then when there is a new function object with that name I update the code, closure and other attributes for all the old function objects to be the same as the new one. (use-package :serapeum)
(defun adder (x)
(flet ((inner (y) (/ x y)))
#'inner))
(defparameter *adders* (dict))
(defun add (x y)
(ensure (@ *adders* x) (adder x))
(funcall (@ *adders* x) y))
(add 3 6) ; => 1/2
(add 3 9) ; => 1/3
;; change / to + in inner
(add 4 9) ; => 13
(add 3 10) ; => 3/10 ctypes.pythonapi.PyFunction_SetClosure.argtypes = [ctypes.py_object, ctypes.py_object]
ctypes.pythonapi.PyFunction_SetClosure(old, new.__closure__)
Also I think you should update __annotations__, __type_params__, __doc__, and __dict__ attributes for the function.