Skip to content

Completion Use Cases

Avishkar Bhoopchand edited this page Jul 2, 2016 · 4 revisions

Popular API Suggestions

Fragment:

import numpy as np
data = np.array([0, 1, 2, 3, 4, 5, 6, 7])
max_value = np.

Suggestions:

max(data)

Fragment:

import numpy as np
data = np.array([0, 1, 2, 3, 4, 5, 6, 7])
value = np.

Suggestions:

max(
min(
argmin(
argmax(
etc...

Fragment:

import numpy as np
size = [10,10]
init = np.

Suggestions:

zeros(size)

Fragment:

import tensorflow as tf
with tf.

Suggestions:

Graph().as_default(), tf.Session() as session:

Fragment:

filename = "Helloworld.txt"
with open

Suggestions:

(filename) as f:

Notes:

Argument Suggestions

Fragment:

import tensorflow as tf
size = 100
vocab_size = 10000
embedding = tf.get_variable

Suggestions:

("embedding", [vocab_size, size])

Fragment:

def count_lines(filename):
    with open(filename) as f:
        return len(f.readlines())

filename = "C:/temp/file1.txt"
count = 

Suggestions:

count_lines(filename)

###Notes: Use attention over all identifiers that are in scope (obtain from AST), may also need an encoding of the function signature to know how many arguments there are etc

Named argument suggestions

Fragment:

def process_file(filename, mode=None, encoding=None):
    with open(filename, mode or "r", encoding=encoding or "utf-8") as f:
        lines = f.read().splitlines()
    print(len(lines))

def dosomething():
    process_file(filename,

Suggestions:

mode=
encoding=

Notes:

Requires attention over function definitions (signatures)

Variable suggestions

Fragment:

class MyClass :
    def fullname ( self , firstname , surname ) :
        fullname = firstname + " " + surname
        return

Suggestions:

fullname

User types: { if | for i in | myvar[ | myvar[i: | return | [x for x in } Suggestions: var1 / arg1 etc Requires attention over all identifiers that are in scope (obtain from AST)

Structure Suggestions User types: { if var1 | def myfunction(self) | for i in range(10) | else | elif | class MyClass } Suggestions: :

Method body Suggestions User types: def init(self, arg1): Suggestions: self.arg1 = arg1 Requires attention over function arguments

Block/body suggestions Context: for i, j in ... | if i == j | ... User types: a[ | b = Suggestions: i / j Requires attention over narrow "scope" (not really the scope because Python uses function-scoping, but it's likely that you'll refer to the closest variables inside the block)