forked from VimPlug/jedi
added magic function names to completion, fixes nothing, but makes jedi more awesome :-D
This commit is contained in:
@@ -108,9 +108,9 @@ class Script(object):
|
||||
completions = []
|
||||
debug.dbg('possible scopes', scopes)
|
||||
for s in scopes:
|
||||
# TODO is this really the right way? just ignore the funcs? \
|
||||
# do the magic functions first? and then recheck here?
|
||||
if not s.isinstance(evaluate.Function):
|
||||
if s.isinstance(evaluate.Function):
|
||||
names = s.get_magic_method_names()
|
||||
else:
|
||||
if isinstance(s, imports.ImportPath):
|
||||
if like == 'import':
|
||||
l = self.module.get_line(self.pos[0])[:self.pos[1]]
|
||||
@@ -119,6 +119,7 @@ class Script(object):
|
||||
names = s.get_defined_names(on_import_stmt=True)
|
||||
else:
|
||||
names = s.get_defined_names()
|
||||
|
||||
for c in names:
|
||||
completions.append((c, s))
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ import sys
|
||||
import os
|
||||
if is_py3k:
|
||||
import io
|
||||
else:
|
||||
import types
|
||||
import inspect
|
||||
|
||||
import debug
|
||||
import parsing
|
||||
import imports
|
||||
import evaluate
|
||||
|
||||
|
||||
def get_sys_path():
|
||||
@@ -157,7 +157,7 @@ class Parser(CachedModule):
|
||||
|
||||
def _get_source(self):
|
||||
""" Override this abstract method """
|
||||
return self._generate_code(self.module, self._load_mixins())
|
||||
return _generate_code(self.module, self._load_mixins())
|
||||
|
||||
def _load_mixins(self):
|
||||
"""
|
||||
@@ -211,7 +211,8 @@ class Parser(CachedModule):
|
||||
mixin_dct['range'] = mixin_dct['xrange']
|
||||
return mixin_dct
|
||||
|
||||
def _generate_code(self, scope, mixin_funcs, depth=0):
|
||||
|
||||
def _generate_code(scope, mixin_funcs={}, depth=0):
|
||||
"""
|
||||
Generate a string, which uses python syntax as an input to the
|
||||
PyFuzzyParser.
|
||||
@@ -301,7 +302,7 @@ class Parser(CachedModule):
|
||||
mixin = mixin_funcs[name]
|
||||
except KeyError:
|
||||
mixin = {}
|
||||
cl_code = self._generate_code(cl, mixin, depth + 1)
|
||||
cl_code = _generate_code(cl, mixin, depth + 1)
|
||||
code += parsing.indent_block(cl_code)
|
||||
code += '\n'
|
||||
|
||||
@@ -450,4 +451,23 @@ class Builtin(object):
|
||||
def scope(self):
|
||||
return self.builtin.parser.module
|
||||
|
||||
@property
|
||||
def magic_function_names(self):
|
||||
try:
|
||||
return self._magic_function_names
|
||||
except AttributeError:
|
||||
# depth = 1 because this is not a module
|
||||
class Container(object):
|
||||
FunctionType = types.FunctionType
|
||||
source = _generate_code(Container, depth=0)
|
||||
parser = parsing.PyFuzzyParser(source, None)
|
||||
# needed for caching (because of weakref)
|
||||
module = self.magic_func_module = parser.module
|
||||
typ = evaluate.follow_path(iter(['FunctionType']), module, module)
|
||||
|
||||
names = typ.pop().get_defined_names()
|
||||
self._magic_function_names = names
|
||||
return names
|
||||
|
||||
|
||||
Builtin = Builtin()
|
||||
|
||||
@@ -457,6 +457,9 @@ class Function(use_metaclass(CachedMetaClass, parsing.Base)):
|
||||
return self
|
||||
return self._decorated_func
|
||||
|
||||
def get_magic_method_names(self):
|
||||
return builtin.Builtin.magic_function_names
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.base_func, name)
|
||||
|
||||
@@ -1561,10 +1564,8 @@ def follow_path(path, scope, call_scope, position=None):
|
||||
else:
|
||||
# The function must not be decorated with something else.
|
||||
if scope.isinstance(Function):
|
||||
# TODO Check default function methods and return them.
|
||||
result = []
|
||||
result = scope.get_magic_method_names()
|
||||
else:
|
||||
# TODO Check magic class methods and return them also.
|
||||
# This is the typical lookup while chaining things.
|
||||
if filter_private_variable(scope, call_scope, current):
|
||||
return []
|
||||
|
||||
@@ -350,3 +350,10 @@ def annot_ret(a:3) -> 3:
|
||||
|
||||
#? str()
|
||||
annot_ret('')
|
||||
|
||||
# -----------------
|
||||
# magic methods
|
||||
# -----------------
|
||||
def a(): pass
|
||||
#? ['__closure__']
|
||||
a.__closure__
|
||||
|
||||
Reference in New Issue
Block a user