I've this function defined in my xonshrc
:
def turn_into_alias(func, keep=False):
aliases[func.__name__] = func
del func
It's supposed to convert a function into an alias. But it doesn't work. It adds the alias all right but the del
eting doesn't work, because it deletes the function reference passed to it.
Is it possible to setup xonsh so that it gives higher priority to the aliases? (probably not, because it's python after all, in that case:)
Is there a way to achieve the effect I want in xonsh?
In Python, and thus xonsh,
del
only modifies the current scope. So in your example, you are really just deleting the namefunc
inside ofturn_into_alias()
. The function object may still have references to it elsewhere so Python won't delete it.Since this is in your xonshrc, probably the simplest thing to do would be to delete it from
globals()
or the__xonsh_ctx__
.Something like the following should work
or