This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients terry.reedy, tetelevm
Date 2021-04-11.00:22:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618100556.18.0.258317109683.issue43654@roundup.psfhosted.org>
In-reply-to
Content
I presume '^' means 'hit Tab'.

The underlying Python problem is that namespaces are conceptually mappings of names (identifiers), a subset of strings, to objects.  Python specifies that the global namespace is a dict, which I believe could mean a dict subclass restricting keys to strings or maybe even identifier strings.  But CPython, at least, uses built-in dicts, allowing any hashable as a key.  Ditto for attribute dicts and locals.  At toplevel, locals() is globals().

(There are a few semi-same uses to non-identifier string completions.
>>> globals()["3.1459"] = None
>>> 3.1459 # 3<tab>
and
>>> globals()['itertools.permutations'] = None
>>> itertools.permutations # itert<tab>
But not recommended or, I believe, guaranteed.)

Completion lists are sorted.  In original Python, sorting was universal.  That was broken for a few types by 2.7.  In 3.x, comparisons and hence sorting were restricted.

Decoding the traceback.  Completion requests are handled in the IDLE interface process.  The remotecall in autocomplete.fetch_completions tries to execute fetch_completions in the user execution process.  That fails trying to sort the list of globals.  The exception is returned with the tag "CALLEXC".  In rpc, decoderesponse filters out various failures and raises the returned exception.

IDLE could filter out non-strings from global and attribute dicts or display a special message.  Or do nothing on the basis that putting non-strings in namespaces and making them unsortable is either a user bug or a consenting adults, do at your own risk and deal with the consequences operation.

Built-in dir() sorts keys and hence it and anything using it fails.

>>> globals()[1]=None
>>> dir()
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    dir()
TypeError: '<' not supported between instances of 'int' and 'str'

Indeed, fetch_completions uses dir(), and this is where it fails.  

Vars() does not sort, allowing one to see the full contents.

>>> vars()
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 1: None}

If one edits a file after putting a non-string in globals, the TypeError is not displayed.  Instead, tab completion is silently disabled and spaces are inserted, just as after applying settings.  This is not good and so a point in favor of doing something.
History
Date User Action Args
2021-04-11 00:22:36terry.reedysetrecipients: + terry.reedy, tetelevm
2021-04-11 00:22:36terry.reedysetmessageid: <1618100556.18.0.258317109683.issue43654@roundup.psfhosted.org>
2021-04-11 00:22:36terry.reedylinkissue43654 messages
2021-04-11 00:22:33terry.reedycreate