bpo-37765: Add keywords to IDLE tab completions (GH-15138)
Keywords are present in the main module tab completion lists generated by rlcompleter, which is used by REPLs on *nix. Add all keywords to IDLE's main module name list except those already added from builtins (True, False, and None) . This list may also be used by Show Completions on the Edit menu, and its hot key. Rewrite Completions doc. Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
This commit is contained in:
parent
1ee5dc1586
commit
bce2eb4646
|
@ -147,7 +147,7 @@ Go to Line
|
||||||
Clear any selection and update the line and column status.
|
Clear any selection and update the line and column status.
|
||||||
|
|
||||||
Show Completions
|
Show Completions
|
||||||
Open a scrollable list allowing selection of keywords and attributes. See
|
Open a scrollable list allowing selection of existing names. See
|
||||||
:ref:`Completions <completions>` in the Editing and navigation section below.
|
:ref:`Completions <completions>` in the Editing and navigation section below.
|
||||||
|
|
||||||
Expand Word
|
Expand Word
|
||||||
|
@ -469,52 +469,58 @@ are restricted to four spaces due to Tcl/Tk limitations.
|
||||||
See also the indent/dedent region commands on the
|
See also the indent/dedent region commands on the
|
||||||
:ref:`Format menu <format-menu>`.
|
:ref:`Format menu <format-menu>`.
|
||||||
|
|
||||||
|
|
||||||
.. _completions:
|
.. _completions:
|
||||||
|
|
||||||
Completions
|
Completions
|
||||||
^^^^^^^^^^^
|
^^^^^^^^^^^
|
||||||
|
|
||||||
Completions are supplied for functions, classes, and attributes of classes,
|
Completions are supplied, when requested and available, for module
|
||||||
both built-in and user-defined. Completions are also provided for
|
names, attributes of classes or functions, or filenames. Each request
|
||||||
filenames.
|
method displays a completion box with existing names. (See tab
|
||||||
|
completions below for an exception.) For any box, change the name
|
||||||
|
being completed and the item highlighted in the box by
|
||||||
|
typing and deleting characters; by hitting :kbd:`Up`, :kbd:`Down`,
|
||||||
|
:kbd:`PageUp`, :kbd:`PageDown`, :kbd:`Home`, and :kbd:`End` keys;
|
||||||
|
and by a single click within the box. Close the box with :kbd:`Escape`,
|
||||||
|
:kbd:`Enter`, and double :kbd:`Tab` keys or clicks outside the box.
|
||||||
|
A double click within the box selects and closes.
|
||||||
|
|
||||||
The AutoCompleteWindow (ACW) will open after a predefined delay (default is
|
One way to open a box is to type a key character and wait for a
|
||||||
two seconds) after a '.' or (in a string) an os.sep is typed. If after one
|
predefined interval. This defaults to 2 seconds; customize it
|
||||||
of those characters (plus zero or more other characters) a tab is typed
|
in the settings dialog. (To prevent auto popups, set the delay to a
|
||||||
the ACW will open immediately if a possible continuation is found.
|
large number of milliseconds, such as 100000000.) For imported module
|
||||||
|
names or class or function attributes, type '.'.
|
||||||
|
For filenames in the root directory, type :data:`os.sep` or
|
||||||
|
data:`os.altsep` immediately after an opening quote. (On Windows,
|
||||||
|
one can specify a drive first.) Move into subdirectories by typing a
|
||||||
|
directory name and a separator.
|
||||||
|
|
||||||
If there is only one possible completion for the characters entered, a
|
Instead of waiting, or after a box is closed, open a completion box
|
||||||
:kbd:`Tab` will supply that completion without opening the ACW.
|
immediately with Show Completions on the Edit menu. The default hot
|
||||||
|
key is :kbd:`C-space`. If one types a prefix for the desired name
|
||||||
|
before opening the box, the first match or near miss is made visible.
|
||||||
|
The result is the same as if one enters a prefix
|
||||||
|
after the box is displayed. Show Completions after a quote completes
|
||||||
|
filenames in the current directory instead of a root directory.
|
||||||
|
|
||||||
'Show Completions' will force open a completions window, by default the
|
Hitting :kbd:`Tab` after a prefix usually has the same effect as Show
|
||||||
:kbd:`C-space` will open a completions window. In an empty
|
Completions. (With no prefix, it indents.) However, if there is only
|
||||||
string, this will contain the files in the current directory. On a
|
one match to the prefix, that match is immediately added to the editor
|
||||||
blank line, it will contain the built-in and user-defined functions and
|
text without opening a box.
|
||||||
classes in the current namespaces, plus any modules imported. If some
|
|
||||||
characters have been entered, the ACW will attempt to be more specific.
|
|
||||||
|
|
||||||
If a string of characters is typed, the ACW selection will jump to the
|
Invoking 'Show Completions', or hitting :kbd:`Tab` after a prefix,
|
||||||
entry most closely matching those characters. Entering a :kbd:`tab` will
|
outside of a string and without a preceding '.' opens a box with
|
||||||
cause the longest non-ambiguous match to be entered in the Editor window or
|
keywords, builtin names, and available module-level names.
|
||||||
Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as
|
|
||||||
will return or a double click. Cursor keys, Page Up/Down, mouse selection,
|
|
||||||
and the scroll wheel all operate on the ACW.
|
|
||||||
|
|
||||||
"Hidden" attributes can be accessed by typing the beginning of hidden
|
When editing code in an editor (as oppose to Shell), increase the
|
||||||
name after a '.', e.g. '_'. This allows access to modules with
|
available module-level names by running your code
|
||||||
``__all__`` set, or to class-private attributes.
|
and not restarting the Shell thereafter. This is especially useful
|
||||||
|
after adding imports at the top of a file. This also increases
|
||||||
|
possible attribute completions.
|
||||||
|
|
||||||
Completions and the 'Expand Word' facility can save a lot of typing!
|
Completion boxes intially exclude names beginning with '_' or, for
|
||||||
|
modules, not included in '__all__'. The hidden names can be accessed
|
||||||
Completions are currently limited to those in the namespaces. Names in
|
by typing '_' after '.', either before or after the box is opened.
|
||||||
an Editor window which are not via ``__main__`` and :data:`sys.modules` will
|
|
||||||
not be found. Run the module once with your imports to correct this situation.
|
|
||||||
Note that IDLE itself places quite a few modules in sys.modules, so
|
|
||||||
much can be found by default, e.g. the re module.
|
|
||||||
|
|
||||||
If you don't like the ACW popping up unbidden, simply make the delay
|
|
||||||
longer or disable the extension.
|
|
||||||
|
|
||||||
.. _calltips:
|
.. _calltips:
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ Released on 2020-10-05?
|
||||||
======================================
|
======================================
|
||||||
|
|
||||||
|
|
||||||
|
bpo-37765: Add keywords to module name completion list. Rewrite
|
||||||
|
Completions section of IDLE doc.
|
||||||
|
|
||||||
bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE
|
bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE
|
||||||
is now always UTF-8.
|
is now always UTF-8.
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ Either on demand or after a user-selected delay after a key character,
|
||||||
pop up a list of candidates.
|
pop up a list of candidates.
|
||||||
"""
|
"""
|
||||||
import __main__
|
import __main__
|
||||||
|
import keyword
|
||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
@ -171,10 +172,13 @@ class AutoComplete:
|
||||||
(what, mode), {})
|
(what, mode), {})
|
||||||
else:
|
else:
|
||||||
if mode == ATTRS:
|
if mode == ATTRS:
|
||||||
if what == "":
|
if what == "": # Main module names.
|
||||||
namespace = {**__main__.__builtins__.__dict__,
|
namespace = {**__main__.__builtins__.__dict__,
|
||||||
**__main__.__dict__}
|
**__main__.__dict__}
|
||||||
bigl = eval("dir()", namespace)
|
bigl = eval("dir()", namespace)
|
||||||
|
kwds = (s for s in keyword.kwlist
|
||||||
|
if s not in {'True', 'False', 'None'})
|
||||||
|
bigl.extend(kwds)
|
||||||
bigl.sort()
|
bigl.sort()
|
||||||
if "__all__" in bigl:
|
if "__all__" in bigl:
|
||||||
smalll = sorted(eval("__all__", namespace))
|
smalll = sorted(eval("__all__", namespace))
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>IDLE — Python 3.9.0a4 documentation</title>
|
<title>IDLE — Python 3.10.0a0 documentation</title>
|
||||||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
||||||
|
|
||||||
<link rel="search" type="application/opensearchdescription+xml"
|
<link rel="search" type="application/opensearchdescription+xml"
|
||||||
title="Search within Python 3.9.0a4 documentation"
|
title="Search within Python 3.10.0a0 documentation"
|
||||||
href="../_static/opensearch.xml"/>
|
href="../_static/opensearch.xml"/>
|
||||||
<link rel="author" title="About these documents" href="../about.html" />
|
<link rel="author" title="About these documents" href="../about.html" />
|
||||||
<link rel="index" title="Index" href="../genindex.html" />
|
<link rel="index" title="Index" href="../genindex.html" />
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
|
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<a href="../index.html">3.9.0a4 Documentation</a> »
|
<a href="../index.html">3.10.0a0 Documentation</a> »
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
||||||
|
@ -201,7 +201,7 @@ be undone.</p>
|
||||||
line visible. A request past the end of the file goes to the end.
|
line visible. A request past the end of the file goes to the end.
|
||||||
Clear any selection and update the line and column status.</p>
|
Clear any selection and update the line and column status.</p>
|
||||||
</dd>
|
</dd>
|
||||||
<dt>Show Completions</dt><dd><p>Open a scrollable list allowing selection of keywords and attributes. See
|
<dt>Show Completions</dt><dd><p>Open a scrollable list allowing selection of existing names. See
|
||||||
<a class="reference internal" href="#completions"><span class="std std-ref">Completions</span></a> in the Editing and navigation section below.</p>
|
<a class="reference internal" href="#completions"><span class="std std-ref">Completions</span></a> in the Editing and navigation section below.</p>
|
||||||
</dd>
|
</dd>
|
||||||
<dt>Expand Word</dt><dd><p>Expand a prefix you have typed to match a full word in the same window;
|
<dt>Expand Word</dt><dd><p>Expand a prefix you have typed to match a full word in the same window;
|
||||||
|
@ -465,38 +465,47 @@ are restricted to four spaces due to Tcl/Tk limitations.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="completions">
|
<div class="section" id="completions">
|
||||||
<span id="id3"></span><h3>Completions<a class="headerlink" href="#completions" title="Permalink to this headline">¶</a></h3>
|
<span id="id3"></span><h3>Completions<a class="headerlink" href="#completions" title="Permalink to this headline">¶</a></h3>
|
||||||
<p>Completions are supplied for functions, classes, and attributes of classes,
|
<p>Completions are supplied, when requested and available, for module
|
||||||
both built-in and user-defined. Completions are also provided for
|
names, attributes of classes or functions, or filenames. Each request
|
||||||
filenames.</p>
|
method displays a completion box with existing names. (See tab
|
||||||
<p>The AutoCompleteWindow (ACW) will open after a predefined delay (default is
|
completions below for an exception.) For any box, change the name
|
||||||
two seconds) after a ‘.’ or (in a string) an os.sep is typed. If after one
|
being completed and the item highlighted in the box by
|
||||||
of those characters (plus zero or more other characters) a tab is typed
|
typing and deleting characters; by hitting <kbd class="kbd docutils literal notranslate">Up</kbd>, <kbd class="kbd docutils literal notranslate">Down</kbd>,
|
||||||
the ACW will open immediately if a possible continuation is found.</p>
|
<kbd class="kbd docutils literal notranslate">PageUp</kbd>, <kbd class="kbd docutils literal notranslate">PageDown</kbd>, <kbd class="kbd docutils literal notranslate">Home</kbd>, and <kbd class="kbd docutils literal notranslate">End</kbd> keys;
|
||||||
<p>If there is only one possible completion for the characters entered, a
|
and by a single click within the box. Close the box with <kbd class="kbd docutils literal notranslate">Escape</kbd>,
|
||||||
<kbd class="kbd docutils literal notranslate">Tab</kbd> will supply that completion without opening the ACW.</p>
|
<kbd class="kbd docutils literal notranslate">Enter</kbd>, and double <kbd class="kbd docutils literal notranslate">Tab</kbd> keys or clicks outside the box.
|
||||||
<p>‘Show Completions’ will force open a completions window, by default the
|
A double click within the box selects and closes.</p>
|
||||||
<kbd class="kbd docutils literal notranslate">C-space</kbd> will open a completions window. In an empty
|
<p>One way to open a box is to type a key character and wait for a
|
||||||
string, this will contain the files in the current directory. On a
|
predefined interval. This defaults to 2 seconds; customize it
|
||||||
blank line, it will contain the built-in and user-defined functions and
|
in the settings dialog. (To prevent auto popups, set the delay to a
|
||||||
classes in the current namespaces, plus any modules imported. If some
|
large number of milliseconds, such as 100000000.) For imported module
|
||||||
characters have been entered, the ACW will attempt to be more specific.</p>
|
names or class or function attributes, type ‘.’.
|
||||||
<p>If a string of characters is typed, the ACW selection will jump to the
|
For filenames in the root directory, type <a class="reference internal" href="os.html#os.sep" title="os.sep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.sep</span></code></a> or
|
||||||
entry most closely matching those characters. Entering a <kbd class="kbd docutils literal notranslate">tab</kbd> will
|
data:<cite>os.altsep</cite> immediately after an opening quote. (On Windows,
|
||||||
cause the longest non-ambiguous match to be entered in the Editor window or
|
one can specify a drive first.) Move into subdirectories by typing a
|
||||||
Shell. Two <kbd class="kbd docutils literal notranslate">tab</kbd> in a row will supply the current ACW selection, as
|
directory name and a separator.</p>
|
||||||
will return or a double click. Cursor keys, Page Up/Down, mouse selection,
|
<p>Instead of waiting, or after a box is closed. open a completion box
|
||||||
and the scroll wheel all operate on the ACW.</p>
|
immediately with Show Completions on the Edit menu. The default hot
|
||||||
<p>“Hidden” attributes can be accessed by typing the beginning of hidden
|
key is <kbd class="kbd docutils literal notranslate">C-space</kbd>. If one types a prefix for the desired name
|
||||||
name after a ‘.’, e.g. ‘_’. This allows access to modules with
|
before opening the box, the first match is displayed.
|
||||||
<code class="docutils literal notranslate"><span class="pre">__all__</span></code> set, or to class-private attributes.</p>
|
The result is the same as if one enters a prefix
|
||||||
<p>Completions and the ‘Expand Word’ facility can save a lot of typing!</p>
|
after the box is displayed. Show Completions after a quote completes
|
||||||
<p>Completions are currently limited to those in the namespaces. Names in
|
filenames in the current directory instead of a root directory.</p>
|
||||||
an Editor window which are not via <code class="docutils literal notranslate"><span class="pre">__main__</span></code> and <a class="reference internal" href="sys.html#sys.modules" title="sys.modules"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.modules</span></code></a> will
|
<p>Hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix usually has the same effect as Show
|
||||||
not be found. Run the module once with your imports to correct this situation.
|
Completions. (With no prefix, it indents.) However, if there is only
|
||||||
Note that IDLE itself places quite a few modules in sys.modules, so
|
one match to the prefix, that match is immediately added to the editor
|
||||||
much can be found by default, e.g. the re module.</p>
|
text without opening a box.</p>
|
||||||
<p>If you don’t like the ACW popping up unbidden, simply make the delay
|
<p>Invoking ‘Show Completions’, or hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix,
|
||||||
longer or disable the extension.</p>
|
outside of a string and without a preceding ‘.’ opens a box with
|
||||||
|
keywords, builtin names, and available module-level names.</p>
|
||||||
|
<p>When editing code in an editor (as oppose to Shell), increase the
|
||||||
|
available module-level names by running your code
|
||||||
|
and not restarting the Shell thereafter. This is especially useful
|
||||||
|
after adding imports at the top of a file. This also increases
|
||||||
|
possible attribute completions.</p>
|
||||||
|
<p>Completion boxes intially exclude names beginning with ‘_’ or, for
|
||||||
|
modules, not included in ‘__all__’. The hidden names can be accessed
|
||||||
|
by typing ‘_’ after ‘.’, either before or after the box is opened.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="calltips">
|
<div class="section" id="calltips">
|
||||||
<span id="id4"></span><h3>Calltips<a class="headerlink" href="#calltips" title="Permalink to this headline">¶</a></h3>
|
<span id="id4"></span><h3>Calltips<a class="headerlink" href="#calltips" title="Permalink to this headline">¶</a></h3>
|
||||||
|
@ -935,7 +944,7 @@ also used for testing.</p>
|
||||||
|
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<a href="../index.html">3.9.0a4 Documentation</a> »
|
<a href="../index.html">3.10.0a0 Documentation</a> »
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
||||||
|
@ -966,7 +975,7 @@ also used for testing.</p>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
Last updated on Mar 07, 2020.
|
Last updated on Jul 08, 2020.
|
||||||
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
|
|
@ -240,8 +240,11 @@ class AutoCompleteTest(unittest.TestCase):
|
||||||
with patch.dict('__main__.__dict__', {'__all__': ['a', 'b']}):
|
with patch.dict('__main__.__dict__', {'__all__': ['a', 'b']}):
|
||||||
s, b = acp.fetch_completions('', ac.ATTRS)
|
s, b = acp.fetch_completions('', ac.ATTRS)
|
||||||
self.assertEqual(s, ['a', 'b'])
|
self.assertEqual(s, ['a', 'b'])
|
||||||
self.assertIn('__name__', b) # From __main__.__dict__
|
self.assertIn('__name__', b) # From __main__.__dict__.
|
||||||
self.assertIn('sum', b) # From __main__.__builtins__.__dict__
|
self.assertIn('sum', b) # From __main__.__builtins__.__dict__.
|
||||||
|
self.assertIn('nonlocal', b) # From keyword.kwlist.
|
||||||
|
pos = b.index('False') # Test False not included twice.
|
||||||
|
self.assertNotEqual(b[pos+1], 'False')
|
||||||
|
|
||||||
# Test attributes with name entity.
|
# Test attributes with name entity.
|
||||||
mock = Mock()
|
mock = Mock()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Add keywords to module name completion list. Rewrite Completions
|
||||||
|
section of IDLE doc.
|
Loading…
Reference in New Issue