Debian Codegraph @

test/completion/stdlib.py

raw symbols SCIP
1 """
2 std library stuff
3 """
4
5 # -----------------
6 # builtins
7 # -----------------
8 arr = ['']
9
10 #? str()
11 sorted(arr)[0]
12
13 #? str()
14 next(reversed(arr))
15 next(reversed(arr))
16
17 # should not fail if there's no return value.
18 def yielder():
19 yield None
20
21 #? None
22 next(reversed(yielder()))
23
24 # empty reversed should not raise an error
25 #?
26 next(reversed())
27
28 #? str()
29 next(open(''))
30
31 #? int()
32 {'a':2}.setdefault('a', 3)
33
34 # Compiled classes should have the meta class attributes.
35 #? ['__itemsize__']
36 tuple.__itemsize__
37 #? []
38 tuple().__itemsize__
39
40 # -----------------
41 # type() calls with one parameter
42 # -----------------
43 #? int
44 type(1)
45 #? int
46 type(int())
47 #? type
48 type(int)
49 #? type
50 type(type)
51 #? list
52 type([])
53
54 def x():
55 yield 1
56 generator = type(x())
57 #? generator
58 type(x for x in [])
59 #? type(x)
60 type(lambda: x)
61
62 import math
63 import os
64 #? type(os)
65 type(math)
66 class X(): pass
67 #? type
68 type(X)
69
70 # -----------------
71 # type() calls with multiple parameters
72 # -----------------
73
74 X = type('X', (object,), dict(a=1))
75
76 # Doesn't work yet.
77 #?
78 X.a
79 #?
80 X
81
82 if os.path.isfile():
83 #? ['abspath']
84 fails = os.path.abspath
85
86 # The type vars and other underscored things from typeshed should not be
87 # findable.
88 #?
89 os._T
90
91
92 with open('foo') as f:
93 for line in f.readlines():
94 #? bytes()
95 line
96 # -----------------
97 # enumerate
98 # -----------------
99 for i, j in enumerate(["as", "ad"]):
100 #? int()
101 i
102 #? str()
103 j
104
105 # -----------------
106 # re
107 # -----------------
108 import re
109 c = re.compile(r'a')
110 # re.compile should not return str -> issue #68
111 #? []
112 c.startswith
113 #? int()
114 c.match().start()
115
116 #? int()
117 re.match(r'a', 'a').start()
118
119 for a in re.finditer('a', 'a'):
120 #? int()
121 a.start()
122
123 # -----------------
124 # ref
125 # -----------------
126 import weakref
127
128 #? int()
129 weakref.proxy(1)
130
131 #? weakref.ref()
132 weakref.ref(1)
133 #? int() None
134 weakref.ref(1)()
135
136 # -----------------
137 # sqlite3 (#84)
138 # -----------------
139
140 import sqlite3
141 #? sqlite3.Connection()
142 con = sqlite3.connect()
143 #? sqlite3.Cursor()
144 c = con.cursor()
145
146 def huhu(db):
147 """
148 :type db: sqlite3.Connection
149 :param db: the db connection
150 """
151 #? sqlite3.Connection()
152 db
153
154 with sqlite3.connect() as c:
155 #? sqlite3.Connection()
156 c
157
158 # -----------------
159 # hashlib
160 # -----------------
161
162 import hashlib
163
164 #? ['md5']
165 hashlib.md5
166
167 # -----------------
168 # copy
169 # -----------------
170
171 import copy
172 #? int()
173 copy.deepcopy(1)
174
175 #?
176 copy.copy()
177
178 # -----------------
179 # json
180 # -----------------
181
182 # We don't want any results for json, because it depends on IO.
183 import json
184 #?
185 json.load('asdf')
186 #?
187 json.loads('[1]')
188
189 # -----------------
190 # random
191 # -----------------
192
193 import random
194 class A(object):
195 def say(self): pass
196 class B(object):
197 def shout(self): pass
198 cls = random.choice([A, B])
199 # TODO why is this not inferred? This used to work...
200 #?
201 cls
202 #? []
203 cls().s
204
205 # -----------------
206 # random
207 # -----------------
208
209 import zipfile
210 z = zipfile.ZipFile("foo")
211 #? ['upper']
212 z.read('name').upper
213
214 # -----------------
215 # contextlib
216 # -----------------
217
218 from typing import Iterator
219 import contextlib
220 with contextlib.closing('asd') as string:
221 #? str()
222 string
223
224 @contextlib.contextmanager
225 def cm1() -> Iterator[float]:
226 yield 1
227 with cm1() as x:
228 #? float()
229 x
230
231 @contextlib.contextmanager
232 def cm2() -> float:
233 yield 1
234 with cm2() as x:
235 #?
236 x
237
238 @contextlib.contextmanager
239 def cm3():
240 yield 3
241 with cm3() as x:
242 #? int()
243 x
244
245 # -----------------
246 # operator
247 # -----------------
248
249 import operator
250
251 f = operator.itemgetter(1)
252 #? float()
253 f([1.0])
254 #? str()
255 f([1, ''])
256
257 g = operator.itemgetter(1, 2)
258 x1, x2 = g([1, 1.0, ''])
259 #? float()
260 x1
261 #? str()
262 x2
263
264 x1, x2 = g([1, ''])
265 #? str()
266 x1
267 #? int() str()
268 x2
269
270 # -----------------
271 # shlex
272 # -----------------
273
274 # Github issue #929
275 import shlex
276 qsplit = shlex.split("foo, ferwerwerw werw werw e")
277 for part in qsplit:
278 #? str()
279 part
280
281 # -----------------
282 # staticmethod, classmethod params
283 # -----------------
284
285 class F():
286 def __init__(self):
287 self.my_variable = 3
288
289 @staticmethod
290 def my_func(param):
291 #? []
292 param.my_
293 #? ['upper']
294 param.uppe
295 #? str()
296 return param
297
298 @staticmethod
299 def my_func_without_call(param):
300 #? []
301 param.my_
302 #? []
303 param.uppe
304 #?
305 return param
306
307 @classmethod
308 def my_method_without_call(cls, param):
309 #?
310 cls.my_variable
311 #? ['my_method', 'my_method_without_call']
312 cls.my_meth
313 #?
314 return param
315
316 @classmethod
317 def my_method(cls, param):
318 #?
319 cls.my_variable
320 #? ['my_method', 'my_method_without_call']
321 cls.my_meth
322 #?
323 return param
324
325 #? str()
326 F.my_func('')
327 #? str()
328 F.my_method('')
329
330 # -----------------
331 # Unknown metaclass
332 # -----------------
333
334 # Github issue 1321
335 class Meta(object):
336 pass
337
338 class Test(metaclass=Meta):
339 def test_function(self):
340 result = super(Test, self).test_function()
341 #? []
342 result.
343
344 # -----------------
345 # Enum
346 # -----------------
347
348 import enum
349
350 class X(enum.Enum):
351 attr_x = 3
352 attr_y = 2.0
353
354 #? ['mro']
355 X.mro
356 #? ['attr_x', 'attr_y']
357 X.attr_
358 #? str()
359 X.attr_x.name
360 #? int()
361 X.attr_x.value
362 #? str()
363 X.attr_y.name
364 #? float()
365 X.attr_y.value
366 #?
367 X().name
368 #? float()
369 X().attr_x.attr_y.value
370
371 # -----------------
372 # functools
373 # -----------------
374 import functools
375
376 basetwo = functools.partial(int, base=2)
377 #? int()
378 basetwo()
379
380 def function(a, b):
381 return a, b
382 a = functools.partial(function, 0)
383
384 #? int()
385 a('')[0]
386 #? str()
387 a('')[1]
388
389 kw = functools.partial(function, b=1.0)
390 tup = kw(1)
391 #? int()
392 tup[0]
393 #? float()
394 tup[1]
395
396 def my_decorator(f):
397 @functools.wraps(f)
398 def wrapper(*args, **kwds):
399 return f(*args, **kwds)
400 return wrapper
401
402 @my_decorator
403 def example(a):
404 return a
405
406 #? str()
407 example('')
408
409 # From GH #1574
410 #? float()
411 functools.wraps(functools.partial(str, 1))(lambda: 1.0)()
412
413 class X:
414 def function(self, a, b):
415 return a, b
416 a = functools.partialmethod(function, 0)
417 kw = functools.partialmethod(function, b=1.0)
418 just_partial = functools.partial(function, 1, 2.0)
419
420 #? int()
421 X().a('')[0]
422 #? str()
423 X().a('')[1]
424
425 # The access of partialmethods on classes are not 100% correct. This doesn't
426 # really matter, because nobody uses it like that anyway and would take quite a
427 # bit of work to fix all of these cases.
428 #? str()
429 X.a('')[0]
430 #?
431 X.a('')[1]
432
433 #? X()
434 X.a(X(), '')[0]
435 #? str()
436 X.a(X(), '')[1]
437
438 tup = X().kw(1)
439 #? int()
440 tup[0]
441 #? float()
442 tup[1]
443
444 tup = X.kw(1)
445 #?
446 tup[0]
447 #? float()
448 tup[1]
449
450 tup = X.kw(X(), 1)
451 #? int()
452 tup[0]
453 #? float()
454 tup[1]
455
456 #? float()
457 X.just_partial('')[0]
458 #? str()
459 X.just_partial('')[1]
460 #? float()
461 X().just_partial('')[0]
462 #? str()
463 X().just_partial('')[1]
464
465 @functools.lru_cache
466 def x() -> int: ...
467 @functools.lru_cache()
468 def y() -> float: ...
469 @functools.lru_cache(8)
470 def z() -> str: ...
471
472 #? int()
473 x()
474 #? float()
475 y()
476 #? str()
477 z()