New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing duplicated definition of magic aliases after reset #11806
Conversation
Hi @juanis2112 ! Thanks for your PR ! I'll try to review it now. |
try: | ||
name = self.magics_manager.magics['line'][cmd] | ||
except KeyError: | ||
self.alias_manager.soft_define_alias(cmd, cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a reasoning to use try:...Except KeyError
instead of checking:
if cmd not in self.magics_manager.magics['line']:
self.alias_manager.soft_define_alias(cmd, cmd)
I would tend to have a preference for the if ...
version , as try/except
could swallow bugs in soft_define_alias
, but I could easily be convinced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @Carreau here: I think it's better to use the if
version and not the try/except
one here.
That is great ! I'll see if I can add a test to make sure there is no later regressions ! Unless you want to add a test; I'm happy to guide you in writing one if you desire. |
Thanks a lot for this @juanis2112! @Carreau, @juanis2112 is working with me in Spyder and I asked her to fix #11646 because it's really annoying for Spyder users. Could you guide her to write a regression test for this? Thanks! |
Of course I will. Side question; it seem GH allow us to give only triage permission to repositories (close issues and manage labels); would that be of interest to you @ccordoba12 ? |
@Carreau I'll be happy to help with the test, with a bit of guidance as @ccordoba12 suggested. |
Sorry, but no. I do the same job for almost all repos in the Spyder organization, so I really don't have time to help you with that. |
It was morre incase there was spyder specific issues here so that you could properly tag them; and more giving more rights that requesting more from you.
Thanks, I'll try to lay out what I believe we should try to do.
|
Ok, so I looked into it a bit more carefully and it is slightly more complicated to write test, so here is what I came up with: modified: IPython/core/tests/test_magic.py
@ test_magic.py:374 @ def test_reset_in_length():
_ip.run_cell("reset -f in")
nt.assert_equal(len(_ip.user_ns['In']), _ip.displayhook.prompt_count+1)
+class TestResertFErrors(TestCase):
+ def test_reset_redefine(self):
+ @magics_class
+ class KernelMagics(Magics):
+ @line_magic
+ def less(self, shell): pass
+ _ip.register_magics(KernelMagics)
+ with self.assertLogs() as cm:
+ # hack, we want to just capture logs, but assertLogs fails if not
+ # logs get produce.
+ # so log one things we ignore.
+ import logging as log_mod
+ log = log_mod.getLogger()
+ log.info('Nothing')
+ # end hack.
+ _ip.run_cell("reset -f")
+ assert len(cm.output) == 1
+ for out in cm.output:
+ assert "Invalid alias" not in out
def test_tb_syntaxerror():
"""test %tb after a SyntaxError"""
ip = get_ipython() You can use it as-is, or try to come up with a better way, but it's tricky enough that I can't request you to write an annoying test case like that. If you just want to change your code from |
@juanis2112 You've done some great contribution, as I wan to release 7.7. soon; I've pushed the test on your branch; and also switched from Try-except to Thanks Again and looking forward to your next contribution. |
@Carreau, thanks a lot for helping @juanis2112 to finish this PR!! I instructed her to work on other Spyder issues in the meantime and we totally forgot about this! |
In that case I accept your offer. I didn't know about the new Github functionality you mentioned above, and I think it'd be really useful in this case. |
No problem, the hard part of the work was down, and it was only annoying details to finish.
I'm not sure the feature is available on all orgs yet, hence why you might not have seen it.Ok, I'll invite you to the right team for that; let me know if you know any body else that would like to be added to triage. |
Fixes #11646 by avoiding the double definition of the magic aliases.