Skip to content

Commit 6015468

Browse files
author
Mikhail Arkhipov
authored
Update Jedi to 0.11.1 (#762)
* Basic tokenizer * Fixed property names * Tests, round I * Tests, round II * tokenizer test * Remove temorary change * Fix merge issue * Merge conflict * Merge conflict * Completion test * Fix last line * Fix javascript math * Make test await for results * Add license headers * Rename definitions to types * License headers * Fix typo in completion details (typo) * Fix hover test * Russian translations * Update to better translation * Fix typo * #70 How to get all parameter info when filling in a function param list * Fix #70 How to get all parameter info when filling in a function param list * Clean up * Clean imports * CR feedback * Trim whitespace for test stability * More tests * Better handle no-parameters documentation * Better handle ellipsis and Python3 * #385 Auto-Indentation doesn't work after comment * #141 Auto indentation broken when return keyword involved * Undo changes * #627 Docstrings for builtin methods are not parsed correctly * reStructuredText converter * Fix: period is not an operator * Minor fixes * Restructure * Tests * Tests * Code heuristics * Baselines * HTML handling * Lists * State machine * Baselines * Squash * no message * Whitespace difference * Update Jedi to 0.11.1 * Enable Travis * Test fixes * Undo change
1 parent b4d8e42 commit 6015468

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+8738
-5798
lines changed

pythonFiles/release/jedi/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
good text editor, while still having very good IDE features for Python.
3737
"""
3838

39-
__version__ = '0.9.0'
39+
__version__ = '0.11.1'
4040

41-
from jedi.api import Script, Interpreter, NotFoundError, set_debug_function
42-
from jedi.api import preload_module, defined_names, names
41+
from jedi.api import Script, Interpreter, set_debug_function, \
42+
preload_module, names
4343
from jedi import settings

pythonFiles/release/jedi/__main__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
from sys import argv
1+
import sys
22
from os.path import join, dirname, abspath, isdir
33

44

5-
if len(argv) == 2 and argv[1] == 'repl':
6-
# don't want to use __main__ only for repl yet, maybe we want to use it for
7-
# something else. So just use the keyword ``repl`` for now.
8-
print(join(dirname(abspath(__file__)), 'api', 'replstartup.py'))
9-
elif len(argv) > 1 and argv[1] == 'linter':
5+
def _start_linter():
106
"""
117
This is a pre-alpha API. You're not supposed to use it at all, except for
128
testing. It will very likely change.
139
"""
1410
import jedi
15-
import sys
1611

1712
if '--debug' in sys.argv:
1813
jedi.set_debug_function()
@@ -37,7 +32,17 @@
3732
print(error)
3833
except Exception:
3934
if '--pdb' in sys.argv:
35+
import traceback
36+
traceback.print_exc()
4037
import pdb
4138
pdb.post_mortem()
4239
else:
4340
raise
41+
42+
43+
if len(sys.argv) == 2 and sys.argv[1] == 'repl':
44+
# don't want to use __main__ only for repl yet, maybe we want to use it for
45+
# something else. So just use the keyword ``repl`` for now.
46+
print(join(dirname(abspath(__file__)), 'api', 'replstartup.py'))
47+
elif len(sys.argv) > 1 and sys.argv[1] == 'linter':
48+
_start_linter()

pythonFiles/release/jedi/_compatibility.py

Lines changed: 116 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,150 @@
66
import imp
77
import os
88
import re
9+
import pkgutil
10+
import warnings
911
try:
1012
import importlib
1113
except ImportError:
1214
pass
1315

16+
# Cannot use sys.version.major and minor names, because in Python 2.6 it's not
17+
# a namedtuple.
1418
is_py3 = sys.version_info[0] >= 3
15-
is_py33 = is_py3 and sys.version_info.minor >= 3
19+
is_py33 = is_py3 and sys.version_info[1] >= 3
20+
is_py34 = is_py3 and sys.version_info[1] >= 4
21+
is_py35 = is_py3 and sys.version_info[1] >= 5
1622
is_py26 = not is_py3 and sys.version_info[1] < 7
23+
py_version = int(str(sys.version_info[0]) + str(sys.version_info[1]))
1724

1825

19-
def find_module_py33(string, path=None):
20-
loader = importlib.machinery.PathFinder.find_module(string, path)
26+
class DummyFile(object):
27+
def __init__(self, loader, string):
28+
self.loader = loader
29+
self.string = string
30+
31+
def read(self):
32+
return self.loader.get_source(self.string)
33+
34+
def close(self):
35+
del self.loader
36+
37+
38+
def find_module_py34(string, path=None, fullname=None):
39+
implicit_namespace_pkg = False
40+
spec = None
41+
loader = None
42+
43+
spec = importlib.machinery.PathFinder.find_spec(string, path)
44+
if hasattr(spec, 'origin'):
45+
origin = spec.origin
46+
implicit_namespace_pkg = origin == 'namespace'
47+
48+
# We try to disambiguate implicit namespace pkgs with non implicit namespace pkgs
49+
if implicit_namespace_pkg:
50+
fullname = string if not path else fullname
51+
implicit_ns_info = ImplicitNSInfo(fullname, spec.submodule_search_locations._path)
52+
return None, implicit_ns_info, False
53+
54+
# we have found the tail end of the dotted path
55+
if hasattr(spec, 'loader'):
56+
loader = spec.loader
57+
return find_module_py33(string, path, loader)
58+
59+
def find_module_py33(string, path=None, loader=None, fullname=None):
60+
loader = loader or importlib.machinery.PathFinder.find_module(string, path)
2161

2262
if loader is None and path is None: # Fallback to find builtins
2363
try:
24-
loader = importlib.find_loader(string)
64+
with warnings.catch_warnings(record=True):
65+
# Mute "DeprecationWarning: Use importlib.util.find_spec()
66+
# instead." While we should replace that in the future, it's
67+
# probably good to wait until we deprecate Python 3.3, since
68+
# it was added in Python 3.4 and find_loader hasn't been
69+
# removed in 3.6.
70+
loader = importlib.find_loader(string)
2571
except ValueError as e:
2672
# See #491. Importlib might raise a ValueError, to avoid this, we
2773
# just raise an ImportError to fix the issue.
28-
raise ImportError("Originally ValueError: " + e.message)
74+
raise ImportError("Originally " + repr(e))
2975

3076
if loader is None:
3177
raise ImportError("Couldn't find a loader for {0}".format(string))
3278

3379
try:
3480
is_package = loader.is_package(string)
3581
if is_package:
36-
module_path = os.path.dirname(loader.path)
37-
module_file = None
82+
if hasattr(loader, 'path'):
83+
module_path = os.path.dirname(loader.path)
84+
else:
85+
# At least zipimporter does not have path attribute
86+
module_path = os.path.dirname(loader.get_filename(string))
87+
if hasattr(loader, 'archive'):
88+
module_file = DummyFile(loader, string)
89+
else:
90+
module_file = None
3891
else:
3992
module_path = loader.get_filename(string)
40-
module_file = open(module_path, 'rb')
93+
module_file = DummyFile(loader, string)
4194
except AttributeError:
4295
# ExtensionLoader has not attribute get_filename, instead it has a
4396
# path attribute that we can use to retrieve the module path
4497
try:
4598
module_path = loader.path
46-
module_file = open(loader.path, 'rb')
99+
module_file = DummyFile(loader, string)
47100
except AttributeError:
48101
module_path = string
49102
module_file = None
50103
finally:
51104
is_package = False
52105

106+
if hasattr(loader, 'archive'):
107+
module_path = loader.archive
108+
53109
return module_file, module_path, is_package
54110

55111

56-
def find_module_pre_py33(string, path=None):
57-
module_file, module_path, description = imp.find_module(string, path)
58-
module_type = description[2]
59-
return module_file, module_path, module_type is imp.PKG_DIRECTORY
112+
def find_module_pre_py33(string, path=None, fullname=None):
113+
try:
114+
module_file, module_path, description = imp.find_module(string, path)
115+
module_type = description[2]
116+
return module_file, module_path, module_type is imp.PKG_DIRECTORY
117+
except ImportError:
118+
pass
119+
120+
if path is None:
121+
path = sys.path
122+
for item in path:
123+
loader = pkgutil.get_importer(item)
124+
if loader:
125+
try:
126+
loader = loader.find_module(string)
127+
if loader:
128+
is_package = loader.is_package(string)
129+
is_archive = hasattr(loader, 'archive')
130+
try:
131+
module_path = loader.get_filename(string)
132+
except AttributeError:
133+
# fallback for py26
134+
try:
135+
module_path = loader._get_filename(string)
136+
except AttributeError:
137+
continue
138+
if is_package:
139+
module_path = os.path.dirname(module_path)
140+
if is_archive:
141+
module_path = loader.archive
142+
file = None
143+
if not is_package or is_archive:
144+
file = DummyFile(loader, string)
145+
return (file, module_path, is_package)
146+
except ImportError:
147+
pass
148+
raise ImportError("No module named {0}".format(string))
60149

61150

62151
find_module = find_module_py33 if is_py33 else find_module_pre_py33
152+
find_module = find_module_py34 if is_py34 else find_module
63153
find_module.__doc__ = """
64154
Provides information about a module.
65155
@@ -71,28 +161,18 @@ def find_module_pre_py33(string, path=None):
71161
"""
72162

73163

164+
class ImplicitNSInfo(object):
165+
"""Stores information returned from an implicit namespace spec"""
166+
def __init__(self, name, paths):
167+
self.name = name
168+
self.paths = paths
169+
74170
# unicode function
75171
try:
76172
unicode = unicode
77173
except NameError:
78174
unicode = str
79175

80-
if is_py3:
81-
u = lambda s: s
82-
else:
83-
u = lambda s: s.decode('utf-8')
84-
85-
u.__doc__ = """
86-
Decode a raw string into unicode object. Do nothing in Python 3.
87-
"""
88-
89-
# exec function
90-
if is_py3:
91-
def exec_function(source, global_map):
92-
exec(source, global_map)
93-
else:
94-
eval(compile("""def exec_function(source, global_map):
95-
exec source in global_map """, 'blub', 'exec'))
96176

97177
# re-raise function
98178
if is_py3:
@@ -147,7 +227,8 @@ def u(string):
147227
"""
148228
if is_py3:
149229
return str(string)
150-
elif not isinstance(string, unicode):
230+
231+
if not isinstance(string, unicode):
151232
return unicode(str(string), 'UTF-8')
152233
return string
153234

@@ -174,6 +255,11 @@ def literal_eval(string):
174255
except ImportError:
175256
from itertools import izip_longest as zip_longest # Python 2
176257

258+
try:
259+
FileNotFoundError = FileNotFoundError
260+
except NameError:
261+
FileNotFoundError = IOError
262+
177263

178264
def no_unicode_pprint(dct):
179265
"""

0 commit comments

Comments
 (0)