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
Autocompletion: Fix issue #3723 -- ordering of completions for magic commands and variables with same name #3801
Conversation
pattern = re.compile("%+") # find % | ||
m = pattern.match(word) # at the start of the string | ||
|
||
print m |
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.
forgotten print.
Requested changes have now been implemented. Ready to merge. |
@@ -177,6 +181,52 @@ def compress_user(path, tilde_expand, tilde_val): | |||
return path | |||
|
|||
|
|||
def uniquify(seq): | |||
"""uniquify a list | |||
i.e. remove duplicate elements, but preserving original order |
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.
One blank line.
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.
This uniquify function is not used in the current version, but it is an
alternative ordering method.
Should I just remove it?
On Fri, Jul 26, 2013 at 6:13 PM, Matthias Bussonnier <
notifications@github.com> wrote:
In IPython/core/completer.py:
@@ -177,6 +181,52 @@ def compress_user(path, tilde_expand, tilde_val):
return path+def uniquify(seq):
- """uniquify a list
- i.e. remove duplicate elements, but preserving original order
One blank line.
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/3801/files#r5436317
.
Dr. David P. Sanders
Profesor Titular "A" / Associate Professor
Departamento de Física, Facultad de Ciencias
Universidad Nacional Autónoma de México (UNAM)
dpsanders@gmail.com
http://sistemas.fciencias.unam.mx/~dsanders
Cubículo / office: #414, 4o. piso del Depto. de Física
Tel.: +52 55 5622 4965
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.
Yes you can remove if it is not used.
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.
Removed.
I would be in favor of a more general way of "ordering" completions. And I am uncomfortable to have it for 1.0. So even if it make sens, I'll stay neutral on this one for the time beeing. |
I believe this is ready to merge. In my opinion, it should definitely go into 1.0 (despite @ivanov 's label) as a stop-gap measure until IPEP 11 |
it's not that big of a problem - most of the time we deal with The reason this is marked for 2.0 is because we already cut an alpha, and then a release candidate for 1.0, and are getting feedback from people who are testing this heavily so that we can release 1.0 that we're fairly confident doesn't have anything majorly broken, and whatever limitations there are should be documented. Completion is a pretty fundamental part of IPython, and delaying this until after 1.0 will actually give us more room to play with it, try new things and really get this right. |
OK, fair enough! |
might be of interest: http://docs.python.org/2/library/difflib.html#sequencematcher-examples |
Yup, to reiterate @ivanov's comment above, there's absolutely no way this is 1.0 material. We're strictly in tiny-fixes and doc touch-up territory at this point. |
I really don't have the bandwidth to work on that proposal now. Sorry to leave you guys hanging. |
Not to worry. Feel free to come back and pick it up whenever you're ready. |
@takluyver and @dpsanders what do we want to do with this PR? |
I'm reluctant to stick yet more complexity into the completer system when we know it's in need of a refactor, but on the other hand we don't know when IPEP 11 might get completed. I guess it depends on how much we want this feature. |
I too am reluctant to add more complexity to the completer code. @fperez do you want to make the call on this one? |
We talked to @fperez last week and we want to move forward with this PR, even without the larger completer refactor. But, @fperez thinks this can be done without using regular expressions (maybe just |
@ellisonbg Apologies for the delay in replying. I'll give it a go when I have a free moment! Basically all that it does is shift the initial |
Have a look at the code in the very first commit of this PR. Is that the kind of thing you mean?:
|
Or:
|
Nice, thanks! |
Quick note, the code suggested above by @ellisonbg won't quite do the correct penalization, as it will make This alternative does the right thing: def penalize_magics_key2(word):
i = word.rfind('%')
if i in (0,1):
s = i+1
return word[s:]+word[:s]
else:
return word and in fact has better behavior than the one proposed here in some edge cases. I wrote up a quick analysis with checks and performance in a notebook so @dpsanders can check. I would suggest using that code (appropriately commented explaining what's going on) instead. It has better behavior and is ~ 2x faster, in addition to being easier to understand for someone who's not a regular expression expert, since it only involves indexing into strings. |
Ah, and one more thing: this PR needs a rebase. |
@fperez Great, thanks. I hope to get to it in the next couple of days, or otherwise at the weekend. |
@fperez Very nice notebook, thanks. I tried my original idea again -- just testing the first couple of characters and moving them to the end if necessary. https://gist.github.com/6723952 (The final version of the code had a Which version do you prefer? |
Sure, we can go with that last one, it's actually easier to understand (clarity matters much more than performance here). Note however that you must change Also keep in mind the need for a rebase. |
…p to the start of the module so that it is not compiled each time
… namespace as a standard variable, to avoid problems if matplotlib is not available to import
…al. Corrected test
…laced the code with the simplest string-based version, removing the regex.
I have put the new code up but I am not understanding how/what to do for the rebase. |
…laced the code with the simplest string-based version, removing the regex.
I skipped all the commits except the last one for the rebase. (Is this legitimate...?) |
@@ -499,6 +536,7 @@ def __init__(self, shell=None, namespace=None, global_namespace=None, | |||
self.file_matches, | |||
self.magic_matches, | |||
self.python_func_kw_matches, | |||
self.alias_matches, |
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.
This dies not exist apparently. Due to @takluyver alias refactoring not so long ago ?
Your user name probably change because you did some commits on another machine where your git user name is not correctly set up. The user will match the email that is registered with |
I finally just reverted to the current master and reimplemented on top. I seem to have made a mess with my github accounts though... |
computo-fc seem to be dpsanders(at)ciencias.unam.mx If it can helps you. |
Yes, thanks, I think that was the problem. And at some point I set the global user.name instead of the local one on the relevant repository. |
@dpsanders is this PR ready for more review? |
Sorry for the delay in replying. From my point of view it's finished, so yes please go ahead and review. |
Of course, by now it probably needs rebasing again! |
No need to rebase |
Looks good to me. |
Merged, thanks! |
:) Thanks, Min! |
And thanks to everybody for comments and reviewing. |
Autocompletion: ordering of completions for magic commands and variables with same name closes ipython#3723 closes ipython#3801
[ not for 1.0 ]
This PR fixes issue #3723.
The introduction of the
%matplotlib
magic broke the order of autocompletions in the sequence of commands described in #3723.This PR fixes this by changing the order in which the completions are returned by the
complete()
function, byintroducing a custom key, called
penalize_magics_key
, which is passed tosorted
to sort the various lists of completions assembled from different places.penalize_magics_key
moves the initial%
or%%
to the end of the key, so that the lexicographic string ordering gives"matplotlib" < "matplotlib%" < "matplotlib%%"
, but all of these are together in the completion list.Added a test function
test_magic_completion_order
which tests that these orderings are correct.