Debian Codegraph @

test/completion/docstring.py

raw symbols SCIP
1 """ Test docstrings in functions and classes, which are used to infer types """
2
3 # -----------------
4 # sphinx style
5 # -----------------
6 def sphinxy(a, b, c, d, x):
7 """ asdfasdf
8 :param a: blablabla
9 :type a: str
10 :type b: (str, int)
11 :type c: random.Random
12 :type d: :class:`random.Random`
13 :param str x: blablabla
14 :rtype: dict
15 """
16 #? str()
17 a
18 #? str()
19 b[0]
20 #? int()
21 b[1]
22 #? ['seed']
23 c.seed
24 #? ['seed']
25 d.seed
26 #? ['lower']
27 x.lower
28
29 #? dict()
30 sphinxy()
31
32 # wrong declarations
33 def sphinxy2(a, b, x, y, z):
34 """
35 :param a: Forgot type declaration
36 :type a:
37 :param b: Just something
38 :type b: ``
39 :param x: Just something without type
40 :param y: A function
41 :type y: def l(): pass
42 :param z: A keyword
43 :type z: return
44 :rtype:
45 """
46 #?
47 a
48 #?
49 b
50 #?
51 x
52 #?
53 y
54 #?
55 z
56
57 #?
58 sphinxy2()
59
60
61 def sphinxy_param_type_wrapped(a):
62 """
63 :param str a:
64 Some description wrapped onto the next line with no space after the
65 colon.
66 """
67 #? str()
68 a
69
70
71 # local classes -> github #370
72 class ProgramNode():
73 pass
74
75 def local_classes(node, node2):
76 """
77 :type node: ProgramNode
78 ... and the class definition after this func definition:
79 :type node2: ProgramNode2
80 """
81 #? ProgramNode()
82 node
83 #? ProgramNode2()
84 node2
85
86 class ProgramNode2():
87 pass
88
89
90 def list_with_non_imports(lst):
91 """
92 Should be able to work with tuples and lists and still import stuff.
93
94 :type lst: (random.Random, [collections.defaultdict, ...])
95 """
96 #? ['seed']
97 lst[0].seed
98
99 import collections as col
100 # use some weird index
101 #? col.defaultdict()
102 lst[1][10]
103
104
105 def two_dots(a):
106 """
107 :type a: json.decoder.JSONDecoder
108 """
109 #? ['raw_decode']
110 a.raw_decode
111
112
113 # sphinx returns
114 def return_module_object():
115 """
116 :rtype: :class:`random.Random`
117 """
118
119 #? ['seed']
120 return_module_object().seed
121
122
123 # -----------------
124 # epydoc style
125 # -----------------
126 def epydoc(a, b):
127 """ asdfasdf
128 @type a: str
129 @param a: blablabla
130 @type b: (str, int)
131 @param b: blablah
132 @rtype: list
133 """
134 #? str()
135 a
136 #? str()
137 b[0]
138
139 #? int()
140 b[1]
141
142 #? list()
143 epydoc()
144
145
146 # Returns with param type only
147 def rparam(a,b):
148 """
149 @type a: str
150 """
151 return a
152
153 #? str()
154 rparam()
155
156
157 # Composite types
158 def composite():
159 """
160 @rtype: (str, int, dict)
161 """
162
163 x, y, z = composite()
164 #? str()
165 x
166 #? int()
167 y
168 #? dict()
169 z
170
171
172 # Both docstring and calculated return type
173 def both():
174 """
175 @rtype: str
176 """
177 return 23
178
179 #? str() int()
180 both()
181
182 class Test(object):
183 def __init__(self):
184 self.teststr = ""
185 """
186 # jedi issue #210
187 """
188 def test(self):
189 #? ['teststr']
190 self.teststr
191
192 # -----------------
193 # statement docstrings
194 # -----------------
195 d = ''
196 """ bsdf """
197 #? str()
198 d.upper()
199
200 # -----------------
201 # class docstrings
202 # -----------------
203
204 class InInit():
205 def __init__(self, foo):
206 """
207 :type foo: str
208 """
209 #? str()
210 foo
211
212
213 class InClass():
214 """
215 :type foo: str
216 """
217 def __init__(self, foo):
218 #? str()
219 foo
220
221
222 class InBoth():
223 """
224 :type foo: str
225 """
226 def __init__(self, foo):
227 """
228 :type foo: int
229 """
230 #? str() int()
231 foo
232
233
234 def __init__(foo):
235 """
236 :type foo: str
237 """
238 #? str()
239 foo
240
241
242 # -----------------
243 # Renamed imports (#507)
244 # -----------------
245
246 import datetime
247 from datetime import datetime as datetime_imported
248
249 def import_issues(foo):
250 """
251 @type foo: datetime_imported
252 """
253 #? datetime.datetime()
254 foo
255
256
257 # -----------------
258 # Doctest completions
259 # -----------------
260
261 def doctest_with_gt():
262 """
263 x
264
265 >>> somewhere_in_docstring = 3
266 #? ['import_issues']
267 >>> import_issu
268 #? ['somewhere_in_docstring']
269 >>> somewhere_
270
271 blabla
272
273 >>> haha = 3
274 #? ['haha']
275 >>> hah
276 #? ['doctest_with_space']
277 >>> doctest_with_sp
278 """
279
280 def doctest_with_space():
281 """
282 x
283 #? ['import_issues']
284 import_issu
285 """
286
287 def doctest_issue_github_1748():
288 """From GitHub #1748
289 #? 10 []
290 This. Al
291 """
292 pass
293
294
295 def docstring_rst_identifiers():
296 """
297 #? 30 ['import_issues']
298 hello I'm here `import_iss` blabla
299
300 #? ['import_issues']
301 hello I'm here `import_iss
302
303 #? []
304 hello I'm here import_iss
305 #? []
306 hello I'm here ` import_iss
307
308 #? ['upper']
309 hello I'm here `str.upp
310 """
311
312
313 def doctest_without_ending():
314 """
315 #? []
316 import_issu
317 ha
318
319 no_ending = False
320 #? ['import_issues']
321 import_issu
322 #? ['no_ending']
323 no_endin