Fixed auto complete issues for Python 2.6

This commit is contained in:
Aditya Toshniwal 2018-08-27 16:37:00 +05:30 committed by Akshay Joshi
parent 7a3f3046df
commit ea787b30eb
3 changed files with 24 additions and 20 deletions

View File

@ -7,6 +7,7 @@
#
##########################################################################
from __future__ import print_function
import sys
import random

View File

@ -11,9 +11,15 @@
import re
import operator
import sys
from itertools import count, repeat, chain
from .completion import Completion
from collections import namedtuple, defaultdict, OrderedDict
from collections import namedtuple, defaultdict
if sys.version_info < (2, 7):
from ordereddict import OrderedDict
else:
from collections import OrderedDict
from .sqlcompletion import (
FromClauseItem, suggest_type, Database, Schema, Table,
Function, Column, View, Keyword, Datatype, Alias, JoinCondition, Join)
@ -286,15 +292,14 @@ class SQLAutoComplete(object):
# This is used when suggesting functions, to avoid the latency that
# would result if we'd recalculate the arg lists each time we suggest
# functions (in large DBs)
self._arg_list_cache = {
usage: {
meta: self._arg_list(meta, usage)
for sch, funcs in self.dbmetadata['functions'].items()
for func, metas in funcs.items()
for meta in metas
}
for usage in ('call', 'call_display', 'signature')
}
self._arg_list_cache = \
dict((usage,
dict((meta, self._arg_list(meta, usage))
for sch, funcs in self.dbmetadata['functions'].items()
for func, metas in funcs.items()
for meta in metas))
for usage in ('call', 'call_display', 'signature'))
def extend_foreignkeys(self, fk_data):
@ -532,11 +537,10 @@ class SQLAutoComplete(object):
c.name for t, cs in scoped_cols.items() if t.ref != ltbl
for c in cs
)
scoped_cols = {
t: [col for col in cols if col.name in other_tbl_cols]
for t, cols in scoped_cols.items()
if t.ref == ltbl
}
scoped_cols = \
dict((t, [col for col in cols if col.name in other_tbl_cols])
for t, cols in scoped_cols.items() if t.ref == ltbl)
lastword = last_word(word_before_cursor, include='most_punctuations')
if lastword == '*':
if suggestion.context == 'insert':
@ -547,10 +551,9 @@ class SQLAutoComplete(object):
p.match(col.default)
for p in self.insert_col_skip_patterns
)
scoped_cols = {
t: [col for col in cols if filter(col)]
for t, cols in scoped_cols.items()
}
scoped_cols = \
dict((t, [col for col in cols if filter(col)])
for t, cols in scoped_cols.items())
if self.asterisk_column_order == 'alphabetic':
for cols in scoped_cols.values():
cols.sort(key=operator.attrgetter('name'))

View File

@ -458,7 +458,7 @@ def suggest_based_on_last_token(token, stmt):
if not schema:
suggestions.append(Schema())
return tuple(suggestions)
elif token_v in {'alter', 'create', 'drop'}:
elif token_v in ['alter', 'create', 'drop']:
return (Keyword(token_v.upper()),)
elif token.is_keyword:
# token is a keyword we haven't implemented any special handling for