gh-69605: PyREPL: insert "import" after "from foo <tab>"#148445
gh-69605: PyREPL: insert "import" after "from foo <tab>"#148445loic-simon wants to merge 3 commits into
Conversation
Improve _pyrepl._module_completer.ModuleCompleter.get_completions:
* "from x.y.z " [tab]-> "from x.y.z import "
* "from foo" [tab]-> "from foo " [tab]-> "from foo import"
(if only one suggestion)
tomasr8
left a comment
There was a problem hiding this comment.
Thanks for the quick PR!
It allows from mat to insert from math import , which I find really smooth and pleasant to use!
This is quite nice indeed!
Sorry, something went wrong.
|
I had the same idea a few days ago. Nice! I'll review soon. |
Sorry, something went wrong.
|
Note: I juste found an existing bug (on main) while testing things 😅 >>> from math .<tab>
>>> from math .ath.integer # instead of `from math .integer` (valid syntax!)It's quite related to this change so I'm inclined to fix it in it's PR, if it's ok (and doesn't turn out too complicated). |
Sorry, something went wrong.
Yeah the parser assumes what you type is at least somewhat valid, but we can fix it if it's not too complicated. I would consider this a bug so we should backport it, could you make a separate PR for it? |
Sorry, something went wrong.
|
You can have subpackages so |
Sorry, something went wrong.
That's the behavior currently proposed by this PR, yes. But I agree that if you're looking for So I guess the question is whether to drop this behavior entirely (eg. only insert I'm leaning slightly toward the first option, because I think the second is less obvious and can be complicated to understand as a user, but I'm happy to try and implement it if we think it's worth it! |
Sorry, something went wrong.
Two import completion improvements:
from math <tab>from mathfrom math importfrom mat<tab>from mathfrom math(extra space)The first one should be pretty uncontroversial, since
importis the only valid syntax here.The second only change the behavior when a single match is found:
from cont<tab>still insertsfrom context(common prefix tocontextlibandcontextvar)from foo<tab>still inserts nothing, since we have no matchIt allows
from mat<tab><tab>to insertfrom math import, which I find really smooth and pleasant to use!Implementation notes: I settled to extend
ImportParser.parseto also return aspace_endboolean, and use that inModuleCompleter.completeto return animportsuggestion / add a space when needed.This is a little more generic that needed for this change (eg. we don't really care abuout the space in
import foo), but it keep the parsing logic and completion logic orthogonal.cc @tomasr8 (it'll have a few conflicts with your coloring PR, but I have no way to point this PR to some virtual "after your PR is merged" branch, have I?)