> Apart from that, what my snippet does is essentially your second
> preference, except that removing an alias from `__dir__` is not
> sufficient to hide it from tab-completion.
It's not just removing it from `__dir__`? What else is needed?
As I hinted at in the code snippet above, the alias cannot be defined in
the ordinary way. Below you can find a minimal example that shows the
difference. Both classes, `A` and `B` have a method `bad`, but in `A` this
method is visible to ipython's tab-completion, in `A` it is not.
As long as it's done automatically without programmer intervention, I
don't feel too strongly about the implementation details. I just don't
want something like adding @remove_alias_from_autocomplete to every
aliased method to become yet another quirk of Sage development that we
need to teach to every new contributor (and retroactively apply to the
codebase).
Well, somehow you will have to tell ipython that a specific alias should
not be visible to tab-completion.
Even if we want to hide all aliases: I don't know whether there is any way
to distinguish an alias from a method defined as usual in python - how
would you?
Best wishes,
Martin
class A:
def good(self):
print(17)
bad = good
def __dir__(self):
return [x for x in super().__dir__() if x != "bad"]
class B:
def __init__(self):
self.__setattr__('bad', self.good)
def good(self):
print(42)
def __dir__(self):
return [x for x in super().__dir__() if x != "bad"]
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/sage-devel/3aff638e-c0b3-43c2-9612-8c88ee0f4fd2n%40googlegroups.com.