Debian Codegraph @

test/completion/imports.py

raw symbols SCIP
1 # -----------------
2 # own structure
3 # -----------------
4
5 # do separate scopes
6 def scope_basic():
7 from import_tree import mod1
8
9 #? int()
10 mod1.a
11
12 #? []
13 import_tree.a
14
15 #? []
16 import_tree.mod1
17
18 import import_tree
19 #? str()
20 import_tree.a
21
22
23 def scope_pkg():
24 import import_tree.mod1
25
26 #? str()
27 import_tree.a
28
29 #? ['mod1']
30 import_tree.mod1
31
32 #? int()
33 import_tree.mod1.a
34
35 def scope_nested():
36 import import_tree.pkg.mod1
37
38 #? str()
39 import_tree.a
40
41 #? list
42 import_tree.pkg.a
43
44 #? ['sqrt']
45 import_tree.pkg.sqrt
46
47 #? ['pkg']
48 import_tree.p
49
50 #? float()
51 import_tree.pkg.mod1.a
52 #? ['a', 'foobar', '__name__', '__package__', '__file__', '__doc__']
53 a = import_tree.pkg.mod1.
54
55 import import_tree.random
56 #? set
57 import_tree.random.a
58
59 def scope_nested2():
60 """Multiple modules should be indexable, if imported"""
61 import import_tree.mod1
62 import import_tree.pkg
63 #? ['mod1']
64 import_tree.mod1
65 #? ['pkg']
66 import_tree.pkg
67
68 # With the latest changes this completion also works, because submodules
69 # are always included (some nested import structures lead to this,
70 # typically).
71 #? ['rename1']
72 import_tree.rename1
73
74 def scope_from_import_variable():
75 """
76 All of them shouldn't work, because "fake" imports don't work in python
77 without the use of ``sys.modules`` modifications (e.g. ``os.path`` see also
78 github issue #213 for clarification.
79 """
80 a = 3
81 #?
82 from import_tree.mod2.fake import a
83 #?
84 from import_tree.mod2.fake import c
85
86 #?
87 a
88 #?
89 c
90
91 def scope_from_import_variable_with_parenthesis():
92 from import_tree.mod2.fake import (
93 a, foobarbaz
94 )
95
96 #?
97 a
98 #?
99 foobarbaz
100 # shouldn't complete, should still list the name though.
101 #? ['foobarbaz']
102 foobarbaz
103
104
105 def as_imports():
106 from import_tree.mod1 import a as xyz
107 #? int()
108 xyz
109 import not_existant, import_tree.mod1 as foo
110 #? int()
111 foo.a
112 import import_tree.mod1 as bar
113 #? int()
114 bar.a
115
116
117 def broken_import():
118 import import_tree.mod1
119 #? import_tree.mod1
120 from import_tree.mod1
121
122 #? 25 import_tree.mod1
123 import import_tree.mod1.
124 #? 25 import_tree.mod1
125 impo5t import_tree.mod1.foo
126 #? 25 import_tree.mod1
127 import import_tree.mod1.foo.
128 #? 31 import_tree.mod1
129 import json, import_tree.mod1.foo.
130
131 # Cases with ;
132 mod1 = 3
133 #? 25 int()
134 import import_tree; mod1.
135 #? 38 import_tree.mod1
136 import_tree; import import_tree.mod1.
137
138 #! ['module json']
139 from json
140
141
142 def test_import_priorities():
143 """
144 It's possible to overwrite import paths in an ``__init__.py`` file, by
145 just assigining something there.
146
147 See also #536.
148 """
149 from import_tree import the_pkg, invisible_pkg
150 #? int()
151 invisible_pkg
152 # In real Python, this would be the module, but it's not, because Jedi
153 # doesn't care about most stateful issues such as __dict__, which it would
154 # need to, to do this in a correct way.
155 #? int()
156 the_pkg
157 # Importing foo is still possible, even though inivisible_pkg got changed.
158 #? float()
159 from import_tree.invisible_pkg import foo
160
161
162 # -----------------
163 # std lib modules
164 # -----------------
165 import tokenize
166 #? ['tok_name']
167 tokenize.tok_name
168
169 from pyclbr import *
170
171 #? ['readmodule_ex']
172 readmodule_ex
173 import os
174
175 #? ['dirname']
176 os.path.dirname
177
178 from os.path import (
179 expanduser
180 )
181
182 #? os.path.expanduser
183 expanduser
184
185 from itertools import (tee,
186 islice)
187 #? ['islice']
188 islice
189
190 from functools import (partial, wraps)
191 #? ['wraps']
192 wraps
193
194 from keyword import kwlist, \
195 iskeyword
196 #? ['kwlist']
197 kwlist
198
199 #? []
200 from keyword import not_existing1, not_existing2
201
202 from tokenize import io
203 tokenize.generate_tokens
204
205 import socket
206 #? 14 ['SocketIO']
207 socket.SocketIO
208
209 # -----------------
210 # builtins
211 # -----------------
212
213 import sys
214 #? ['prefix']
215 sys.prefix
216
217 #? ['append']
218 sys.path.append
219
220 from math import *
221 #? ['cos', 'cosh']
222 cos
223
224 def func_with_import():
225 import time
226 return time
227
228 #? ['sleep']
229 func_with_import().sleep
230
231 # -----------------
232 # relative imports
233 # -----------------
234
235 from .import_tree import mod1
236 #? int()
237 mod1.a
238
239 from ..import_tree import mod1
240 #?
241 mod1.a
242
243 from .......import_tree import mod1
244 #?
245 mod1.a
246
247 from .. import helpers
248 #? int()
249 helpers.sample_int
250
251 from ..helpers import sample_int as f
252 #? int()
253 f
254
255 from . import run
256 #? []
257 run.
258
259 from . import import_tree as imp_tree
260 #? str()
261 imp_tree.a
262
263 from . import datetime as mod1
264 #? []
265 mod1.
266
267 # self import
268 # this can cause recursions
269 from imports import *
270
271 # -----------------
272 # packages
273 # -----------------
274
275 from import_tree.mod1 import c
276 #? set
277 c
278
279 from import_tree import recurse_class1
280
281 #? ['a']
282 recurse_class1.C.a
283 # github #239 RecursionError
284 #? ['a']
285 recurse_class1.C().a
286
287 # -----------------
288 # Jedi debugging
289 # -----------------
290
291 # memoizing issues (check git history for the fix)
292 import not_existing_import
293
294 if not_existing_import:
295 a = not_existing_import
296 else:
297 a = not_existing_import
298 #?
299 a
300
301 # -----------------
302 # module underscore descriptors
303 # -----------------
304
305 def underscore():
306 import keyword
307 #? ['__file__']
308 keyword.__file__
309 #? str()
310 keyword.__file__
311
312 # Does that also work for our own module?
313 #? ['__file__']
314 __file__
315
316
317 # -----------------
318 # complex relative imports #784
319 # -----------------
320 def relative():
321 #? ['foobar']
322 from import_tree.pkg.mod1 import foobar
323 #? int()
324 foobar
325 return 1