About Python Autocompletion

Tips and tricks to get the most out of using Editra

About Python Autocompletion

Postby cody » Mon Oct 13, 2008 5:39 pm

The current auto-completion implementation for Python in Editra works as follows.

1) The file is parsed and all the business in the code is stripped out to create a skeleton module of the code. This is to make it safe to use for introspection, though it will under some contexts cause member attributes to not be shown in the choices for auto-completion (i.e self.myattr).

2) This code is then compiled and executed in a temporary namespace for introspection.

3) If matching results for the piece of code that is being checked exist then the tips are shown.

This happens when:

1) The document you are editing is recognized as Python by Editra (i.e the syntax highlighting is python.)

2) You type a '(' or '.' in the document. Then the steps mentioned above will be performed for the code segment directly to the left of these two characters.

Code: Select all
import sys

sys.


In this example a list of what is available in the 'sys' module will be shown after typing the '.'

Code: Select all
path="myfile.txt"
open(


In this example the signature for the builtin 'open' function will be shown right after typing the '('.

The auto-completion can operate in most cases and can correctly show results for objects in the current file as well as any file that is imported into that file so long as the import path for that module is relative to the current document or is a system module.

The current support for this feature was written mostly as a proof of concept implementation to give me some extra tools to help with developing Editra. It will be re-written (probably completely) at some point.
User avatar
cody
Site Admin
 
Posts: 1314
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: About Python Autocompletion

Postby fberger » Thu Feb 21, 2013 8:44 am

cody wrote:This happens when:
[...]
2) You type a '(' or '.' in the document. Then the steps mentioned above will be performed for the code segment directly to the left of these two characters.


The problem with this approach is that Editra may severly slow down when typing a dot or a bracket. IMHO it would be preferable to precalculate the most common cases in a low-priority backgorund thread, or to use a faster parsing mechanism.

cody wrote:The current support for this feature was written mostly as a proof of concept implementation to give me some extra tools to help with developing Editra. It will be re-written (probably completely) at some point.


That explains the slowness, and a re-write at some point sounds good. :)
fberger
User
 
Posts: 27
Joined: Mon Jul 05, 2010 9:53 am
Location: Germany

Re: About Python Autocompletion

Postby cody » Thu Feb 21, 2013 2:08 pm

The parsing is actually quite fast and uses almost no time. Most of the time usually comes from asking the python interpreter to enumerate the list of options from an objects __dict__ or from the importing of large external modules into the namespace (i.e. wx).

The optimal version of the autocompleter would actually run in a separate process using the version of python that the user has installed on the system and has selected as their working version.
User avatar
cody
Site Admin
 
Posts: 1314
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: About Python Autocompletion

Postby fberger » Thu Feb 21, 2013 3:07 pm

cody wrote:The optimal version of the autocompleter would actually run in a separate process using the version of python that the user has installed on the system and has selected as their working version.


+1 :)
fberger
User
 
Posts: 27
Joined: Mon Jul 05, 2010 9:53 am
Location: Germany


Return to Usage Tips

Who is online

Users browsing this forum: No registered users and 1 guest

cron