I want to make two functions equal to each other, for example:
def fn_maker(fn_signature): def _fn(): pass _fn.signature = fn_signature return _fn
How can I do it? I know that I could override eq
and ne
if fa, fb, fc are instances of some class. But here eq is not in the dir (fa) directory and adds that the list is not working. I figured out a workaround, like using a cache, for example,
def fn_maker(fn_signature): if fn_signature in fn_maker.cache: return fn_maker.cache[fn_signature] def _fn(): pass _fn.signature = fn_signature fn_maker.cache[fn_signature] = _fn return _fn fn_maker.cache = {}
Thus, there is a guarantee that there is only one function for the same signature value (sort of like singleton). But I'm really looking for some simpler solutions.
source share