Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87573 > unrolled thread
| Started by | candide <c.candide@laposte.net> |
|---|---|
| First post | 2015-03-16 09:23 -0700 |
| Last post | 2015-03-18 01:07 +0000 |
| Articles | 10 — 7 participants |
Back to article view | Back to comp.lang.python
Auto-completion: why not module name? candide <c.candide@laposte.net> - 2015-03-16 09:23 -0700
Re: Auto-completion: why not module name? Chris Angelico <rosuav@gmail.com> - 2015-03-17 03:40 +1100
Re: Auto-completion: why not module name? Jonas Wielicki <jonas@wielicki.name> - 2015-03-16 17:54 +0100
Re: Auto-completion: why not module name? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-16 10:57 -0600
Re: Auto-completion: why not module name? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-17 19:10 +1100
Re: Auto-completion: why not module name? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-03-17 12:22 +0000
Re: Auto-completion: why not module name? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-18 09:54 +1100
Auto-completion of Unicode names [was why not module name?] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-18 10:29 +1100
Re: Auto-completion of Unicode names [was why not module name?] Chris Angelico <rosuav@gmail.com> - 2015-03-18 11:06 +1100
Re: Auto-completion of Unicode names [was why not module name?] Dan Sommers <dan@tombstonezero.net> - 2015-03-18 01:07 +0000
| From | candide <c.candide@laposte.net> |
|---|---|
| Date | 2015-03-16 09:23 -0700 |
| Subject | Auto-completion: why not module name? |
| Message-ID | <18705a55-6b0a-4b55-99ab-479c19566e1a@googlegroups.com> |
Python 3.4 provides auto-completion facility within a Python console embedded in a command line terminal. But apparently this facility doesn't allow the user to complete with standard module name. For instance, editing the following : >>> import ma and hitting the TAB key doesn't generate math as I was expecting but the following strings : map( max( [tested on Ubuntu 12.10] Is it the expected behaviour ?
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-03-17 03:40 +1100 |
| Message-ID | <mailman.451.1426524036.21433.python-list@python.org> |
| In reply to | #87573 |
On Tue, Mar 17, 2015 at 3:23 AM, candide <c.candide@laposte.net> wrote: > Python 3.4 provides auto-completion facility within a Python console embedded in a command line terminal. > > > But apparently this facility doesn't allow the user to complete with standard module name. For instance, editing the following : > >>>> import ma > > and hitting the TAB key doesn't generate > > math > > as I was expecting but the following strings : > > map( max( > > [tested on Ubuntu 12.10] > > Is it the expected behaviour ? Looks to me like it's just doing the normal tab-completion of globals, rather than having a special case for the 'import' statement. So what you're talking about here is a feature request: When the input begins "import ", please can tab-completion enumerate available modules? This is a very plausible feature request, but be aware that it will involve a very costly disk search. Figuring out what modules could be imported means going through the entire Python module search path, enumerating .py (and other) files, and that could be a lot slower than you think. It might even already be available, but disabled by default (because of that cost). But someone other than me will be better placed to answer that. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Jonas Wielicki <jonas@wielicki.name> |
|---|---|
| Date | 2015-03-16 17:54 +0100 |
| Message-ID | <mailman.452.1426524875.21433.python-list@python.org> |
| In reply to | #87573 |
[Multipart message — attachments visible in raw view] — view raw
On 16.03.2015 17:40, Chris Angelico wrote:
> This is a very plausible feature request, but be aware that it will
> involve a very costly disk search. Figuring out what modules could be
> imported means going through the entire Python module search path,
> enumerating .py (and other) files, and that could be a lot slower than
> you think.
With possible side-effects, like help("modules") has. I don’t think that
this is a trivial task (and if it is, why is help("modules") not
implemented in that trivial way?)
regards,
jwi
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-03-16 10:57 -0600 |
| Message-ID | <mailman.454.1426525083.21433.python-list@python.org> |
| In reply to | #87573 |
On Mon, Mar 16, 2015 at 10:40 AM, Chris Angelico <rosuav@gmail.com> wrote: > Looks to me like it's just doing the normal tab-completion of globals, > rather than having a special case for the 'import' statement. So what > you're talking about here is a feature request: > > When the input begins "import ", please can tab-completion enumerate > available modules? > > This is a very plausible feature request, but be aware that it will > involve a very costly disk search. Figuring out what modules could be > imported means going through the entire Python module search path, > enumerating .py (and other) files, and that could be a lot slower than > you think. Completeness would also be an issue. There is no general requirement that module finders use the file system at all (one could write a finder and loader to import modules from the network, for instance), nor is there any API for enumerating the modules available. Another difficulty would be packages. You can't generally know whether foo.bar is a module until you've already imported foo.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2015-03-17 19:10 +1100 |
| Message-ID | <5507e181$0$11104$c3e8da3@news.astraweb.com> |
| In reply to | #87573 |
On Tuesday 17 March 2015 03:23, candide wrote:
> Python 3.4 provides auto-completion facility within a Python console
> embedded in a command line terminal.
>
>
> But apparently this facility doesn't allow the user to complete with
> standard module name. For instance, editing the following :
>
>>>> import ma
>
> and hitting the TAB key doesn't generate
>
> math
>
> as I was expecting but the following strings :
You might like my tab completion and command history module:
http://code.google.com/p/tabhistory/
I've been using it on Linux for about three or four years, and although I
don't promise it is bug-free, it shouldn't blow up your computer :-)
It supports module completion in `import` and `from ... import` statements.
It even supports module attribute completion if the module is already
cached.
E.g. if the re module is cached, typing
from re import ma[TAB}
will compete the "ma" to "match".
By default, the tabhistory module:
* indents at the start of the line
* completes on module names in `import` and `from` statements
* completes on file names inside strings
* and completes on global and builtin names and keywords everywhere else.
You can read an announcement here:
http://code.activestate.com/lists/python-list/672898/
Feedback from Mac and Windows users is very, very welcome.
--
Steve
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2015-03-17 12:22 +0000 |
| Message-ID | <mailman.494.1426594982.21433.python-list@python.org> |
| In reply to | #87627 |
On 17 March 2015 at 08:10, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Tuesday 17 March 2015 03:23, candide wrote:
>
> You might like my tab completion and command history module:
>
> http://code.google.com/p/tabhistory/
>
> I've been using it on Linux for about three or four years, and although I
> don't promise it is bug-free, it shouldn't blow up your computer :-)
Good work Steven. I just gave it a try and it works great.
> It supports module completion in `import` and `from ... import` statements.
> It even supports module attribute completion if the module is already
> cached.
>
> E.g. if the re module is cached, typing
>
> from re import ma[TAB}
>
> will compete the "ma" to "match".
BTW ipython does this and goes one step further. It basically imports
the module while tab completion is ongoing so that you can complete
"from ...import" without needing to import the module first. In
principle that could be problematic but in practice I find it useful
and it has never caused me any actual problems.
> By default, the tabhistory module:
>
> * indents at the start of the line
Any reason for using 8 spaces for a tab? Or is that just my terminal
(gnome-terminal)?
> * completes on module names in `import` and `from` statements
> * completes on file names inside strings
I'm not sure what causes this but I have a symlink in my user
directory called "current" that just takes me to the things I'm
currently working on. When I tab complete it it puts in a quote
character:
>>> with open('current'
I think it thinks that "current" is a complete filename when it's
actually a symlink to a directory containing other things. If I delete
the quote and add a slash then it continues to complete normally.
Not sure if it's relevant but my .inputrc has:
set mark-symlinked-directories on
This setting changes the way that symlinks to directories are
completed so that a slash is automatically added when I tab complete
them.
> * and completes on global and builtin names and keywords everywhere else.
>
> You can read an announcement here:
>
> http://code.activestate.com/lists/python-list/672898/
>
> Feedback from Mac and Windows users is very, very welcome.
On Linux unfortunately.
Oscar
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2015-03-18 09:54 +1100 |
| Message-ID | <5508b0aa$0$12988$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #87635 |
On Tue, 17 Mar 2015 11:22 pm, Oscar Benjamin wrote:
> On 17 March 2015 at 08:10, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> On Tuesday 17 March 2015 03:23, candide wrote:
>>
>> You might like my tab completion and command history module:
>>
>> http://code.google.com/p/tabhistory/
>>
>> I've been using it on Linux for about three or four years, and although I
>> don't promise it is bug-free, it shouldn't blow up your computer :-)
>
> Good work Steven. I just gave it a try and it works great.
Thank you!
>> It supports module completion in `import` and `from ... import`
>> statements. It even supports module attribute completion if the module is
>> already cached.
>>
>> E.g. if the re module is cached, typing
>>
>> from re import ma[TAB}
>>
>> will compete the "ma" to "match".
>
> BTW ipython does this and goes one step further. It basically imports
> the module while tab completion is ongoing so that you can complete
> "from ...import" without needing to import the module first. In
> principle that could be problematic but in practice I find it useful
> and it has never caused me any actual problems.
I thought about that, but I decided against it because of the security risk:
from evil_module_of_doom import something
Just tab-completing the name "something" shouldn't run the evil module. I
suppose I could add it as an optional feature, defaulting to off. Or try
parsing the source code.
>> By default, the tabhistory module:
>>
>> * indents at the start of the line
>
> Any reason for using 8 spaces for a tab? Or is that just my terminal
> (gnome-terminal)?
By default, it should indent with an actual tab character, which most
terminals treat as 8-spaces wide. But you can change that by setting
completer.indent to whatever string you want. Are you sure it is using
actual spaces?
>> * completes on module names in `import` and `from` statements
>> * completes on file names inside strings
>
> I'm not sure what causes this but I have a symlink in my user
> directory called "current" that just takes me to the things I'm
> currently working on. When I tab complete it it puts in a quote
> character:
>
>>>> with open('current'
>
> I think it thinks that "current" is a complete filename when it's
> actually a symlink to a directory containing other things. If I delete
> the quote and add a slash then it continues to complete normally.
Weird. It shouldn't be adding a close quote. Mind you, there appears to be
at least one other bug in the file name completion, so I need to work on
that soon.
However, I can reproduce the bug, so I'll work on that too. Thank you for
the report!
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2015-03-18 10:29 +1100 |
| Subject | Auto-completion of Unicode names [was why not module name?] |
| Message-ID | <5508b8f3$0$13014$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #87573 |
Speaking of tab completion, would anyone be interested in being able to
auto-complete \N{...} unicode character names? I'm considering that as an
enhancement to my tabhistory module.
Python supports \N{...} backslash escapes in Unicode strings, so we can
write things like:
py> print(u"\N{CYRILLIC CAPITAL LETTER ZE WITH DESCENDER}")
Ҙ
There are currently somewhere in the vicinity of 110 thousand such names.
Any interest?
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-03-18 11:06 +1100 |
| Subject | Re: Auto-completion of Unicode names [was why not module name?] |
| Message-ID | <mailman.506.1426637189.21433.python-list@python.org> |
| In reply to | #87655 |
On Wed, Mar 18, 2015 at 10:29 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Speaking of tab completion, would anyone be interested in being able to
> auto-complete \N{...} unicode character names? I'm considering that as an
> enhancement to my tabhistory module.
>
> Python supports \N{...} backslash escapes in Unicode strings, so we can
> write things like:
>
> py> print(u"\N{CYRILLIC CAPITAL LETTER ZE WITH DESCENDER}")
> Ҙ
>
>
> There are currently somewhere in the vicinity of 110 thousand such names.
Not from me, no. I don't usually use \N escapes - it's usually easiest
to do an external search to figure out the code point, and then either
paste in the character itself (assuming it's not a combining
character, or whitespace, or something, where the loss of clarity
would be a problem), or just use a \u or \U escape. If I knew the
names perfectly, then I might use \N escapes, but even with tab
completion, they'd be quite slow to key in.
How many people actually use \N escapes and hand-enter them?
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dan Sommers <dan@tombstonezero.net> |
|---|---|
| Date | 2015-03-18 01:07 +0000 |
| Subject | Re: Auto-completion of Unicode names [was why not module name?] |
| Message-ID | <meaj4b$hr0$1@dont-email.me> |
| In reply to | #87655 |
On Wed, 18 Mar 2015 10:29:53 +1100, Steven D'Aprano wrote:
> Speaking of tab completion, would anyone be interested in being able
> to auto-complete \N{...} unicode character names? I'm considering that
> as an enhancement to my tabhistory module.
Only if it's fuzzy. One use case is that "opening curly quote"
character, except that I don't remember that it's actually a "left
double quotation mark." Once I type "open," or "quot," no amount of
ordinary left-to-right / startswith completion will help me. And if I
have to look it up somewhere, then I can probably just copy/paste an
actual character or a U+XXXX code once I find it.
> Python supports \N{...} backslash escapes in Unicode strings, so we
> can write things like:
>
> py> print(u"\N{CYRILLIC CAPITAL LETTER ZE WITH DESCENDER}")
> Ҙ
Or I can just enter Ҙ directly using my OS' preferred input method(s),
which is in all likelihood easier and more familiar and comfortable¹ for
someone who has a need for a Ҙ in the first place. (I am not one of
those people; I just copied and pasted the Ҙ that you provided.)
> There are currently somewhere in the vicinity of 110 thousand such
> names.
I think you just made my point about the completion being fuzzy. ;-)
Dan
¹ Okay, so that's just an *opinion*.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web