Martin Panter added the comment:

I moved all the calls targetting the readline module into a ReadlineCompleter 
subclass. However the logic for parsing “import” statements still exists in the 
base Completer class in private methods. An overview of the two classes:

class Completer:
    def complete(self, text, state):
        self._get_matches(text)
    def _get_matches(text):
        # Only completes global and object.attr names, like before
    def _code_matches(self, code, ...):
        # Completes import statements, otherwise returns (None, ...)

class ReadlineCompleter(Completer):  # New public class
    def complete(self, text, state):
        # Moved Yury’s Tab insertion logic here
        return super().complete(...)
    def _get_matches(text):
        code = readline.get_line_buffer()[:readline.get_endidx()]
        self._code_matches(code)
        super()._get_matches(text)  # Fallback to existing behaviour

Perhaps the _code_matches() and related methods could be turned into more 
general public APIs, e.g. complete_code(code) -> list of modules, attributes, 
globals, etc. But that would affect global_matches() and attr_matches(), which 
I have not touched so far.

Other changes:
* Limit underscore-prefixed completions, consistent with Issue 25011; see new 
_filter_identifiers() method
* Changed the demo in the documentation; attributes like __doc__ are omitted by 
default
* Removed workaround for non-ASCII input in favour of fixing Issue 16182

----------
dependencies: +readline: Wrong tab completion scope indices in Unicode terminals
Added file: http://bugs.python.org/file42986/complete-import.v2.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25419>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to