forked from VimPlug/jedi
changing completion of python file objects
This commit is contained in:
@@ -4,13 +4,13 @@ import os
|
||||
import time
|
||||
|
||||
try:
|
||||
if not os.name == 'nt':
|
||||
if os.name == 'nt':
|
||||
# does not work on Windows, as pyreadline and colorama interfere
|
||||
raise ImportError
|
||||
else:
|
||||
# Use colorama for nicer console output.
|
||||
from colorama import Fore, init
|
||||
init()
|
||||
# does not work on Windows, as pyreadline and colorama interfere
|
||||
else:
|
||||
raise ImportError
|
||||
except ImportError:
|
||||
class Fore(object):
|
||||
RED = ''
|
||||
|
||||
@@ -6,7 +6,7 @@ import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
from jedi._compatibility import builtins as _builtins, is_py3k, exec_function
|
||||
from jedi._compatibility import builtins as _builtins, exec_function
|
||||
from jedi import debug
|
||||
from jedi.parser.representation import Base
|
||||
from jedi.cache import underscore_memoization
|
||||
@@ -22,6 +22,7 @@ class PyObject(Base):
|
||||
# comply with the parser
|
||||
start_pos = 0, 0
|
||||
asserts = []
|
||||
path = None # modules have this attribute - set it to None.
|
||||
|
||||
def __init__(self, obj, parent=None):
|
||||
self.obj = obj
|
||||
@@ -183,12 +184,6 @@ docstr_defaults = {
|
||||
'string': 'str',
|
||||
}
|
||||
|
||||
if is_py3k:
|
||||
#docstr_defaults['file object'] = 'import io; return io.TextIOWrapper()'
|
||||
pass # TODO reenable
|
||||
else:
|
||||
docstr_defaults['file object'] = 'file'
|
||||
|
||||
|
||||
def _parse_function_doc(doc):
|
||||
"""
|
||||
|
||||
@@ -11,6 +11,7 @@ import inspect
|
||||
from jedi._compatibility import is_py3k, builtins
|
||||
from jedi.parser import Parser
|
||||
from jedi.parser.representation import Class
|
||||
from jedi.evaluate.helpers import FakeName
|
||||
|
||||
modules = {}
|
||||
|
||||
@@ -76,16 +77,24 @@ def _load_faked_module(module):
|
||||
except IOError:
|
||||
return
|
||||
module = Parser(source, module_name).module
|
||||
if module_name == 'builtins' and not is_py3k:
|
||||
# There are two implementations of `open` for either python 2/3.
|
||||
# -> Rename the python2 version.
|
||||
open_func = search_scope(module, 'open')
|
||||
open_func.name = FakeName('open_python3')
|
||||
open_func = search_scope(module, 'open_python2')
|
||||
open_func.name = FakeName('open')
|
||||
modules[module_name] = module
|
||||
return module
|
||||
|
||||
|
||||
def _faked(module, obj, name=None):
|
||||
def from_scope(scope, obj_name):
|
||||
for s in scope.subscopes:
|
||||
if str(s.name) == obj_name:
|
||||
return s
|
||||
def search_scope(scope, obj_name):
|
||||
for s in scope.subscopes:
|
||||
if str(s.name) == obj_name:
|
||||
return s
|
||||
|
||||
|
||||
def _faked(module, obj, name=None):
|
||||
# Crazy underscore actions to try to escape all the internal madness.
|
||||
obj = obj.__class__ if is_class_instance(obj) else obj
|
||||
if module is None:
|
||||
@@ -110,21 +119,21 @@ def _faked(module, obj, name=None):
|
||||
# for methods.
|
||||
if name is None:
|
||||
if inspect.isbuiltin(obj):
|
||||
return from_scope(faked_mod, obj.__name__)
|
||||
return search_scope(faked_mod, obj.__name__)
|
||||
elif not inspect.isclass(obj):
|
||||
# object is a method or descriptor
|
||||
cls = from_scope(faked_mod, obj.__objclass__.__name__)
|
||||
cls = search_scope(faked_mod, obj.__objclass__.__name__)
|
||||
if cls is None:
|
||||
return
|
||||
return from_scope(cls, obj.__name__)
|
||||
return search_scope(cls, obj.__name__)
|
||||
else:
|
||||
if obj == module:
|
||||
return from_scope(faked_mod, name)
|
||||
return search_scope(faked_mod, name)
|
||||
else:
|
||||
cls = from_scope(faked_mod, obj.__name__)
|
||||
cls = search_scope(faked_mod, obj.__name__)
|
||||
if cls is None:
|
||||
return
|
||||
return from_scope(cls, name)
|
||||
return search_scope(cls, name)
|
||||
|
||||
|
||||
def get_faked(*args, **kwargs):
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class TextIOWrapper():
|
||||
def __next__(self):
|
||||
return ''
|
||||
return 'hacked io return'
|
||||
|
||||
@@ -45,6 +45,15 @@ class xrange():
|
||||
return 1
|
||||
|
||||
|
||||
def open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True):
|
||||
import io
|
||||
return io.TextIOWrapper(file, mode, buffering, encoding, errors, newline, closefd)
|
||||
|
||||
|
||||
def open_python2(name, mode=None, buffering=None):
|
||||
return file(name, mode, buffering)
|
||||
|
||||
|
||||
#--------------------------------------------------------
|
||||
# descriptors
|
||||
#--------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user