Debian Codegraph @

test/completion/pep0484_comments.py

raw symbols SCIP
1 a = 3 # type: str
2 #? str()
3 a
4
5 b = 3 # type: str but I write more
6 #? int()
7 b
8
9 c = 3 # type: str # I comment more
10 #? str()
11 c
12
13 d = "It should not read comments from the next line"
14 # type: int
15 #? str()
16 d
17
18 # type: int
19 e = "It should not read comments from the previous line"
20 #? str()
21 e
22
23 class BB: pass
24
25 def test(a, b):
26 a = a # type: BB
27 c = a # type: str
28 d = a
29 # type: str
30 e = a # type: str # Should ignore long whitespace
31
32 #? BB()
33 a
34 #? str()
35 c
36 #? BB()
37 d
38 #? str()
39 e
40
41 class AA:
42 class BB:
43 pass
44
45 def test(a):
46 # type: (AA.BB) -> None
47 #? AA.BB()
48 a
49
50 def test(a):
51 # type: (AA.BB,) -> None
52 #? AA.BB()
53 a
54
55 a,b = 1, 2 # type: str, float
56 #? str()
57 a
58 #? float()
59 b
60
61 class Employee:
62 pass
63
64 from typing import List, Tuple
65 x = [] # type: List[Employee]
66 #? Employee()
67 x[1]
68 x, y, z = [], [], [] # type: List[int], List[int], List[str]
69 #? int()
70 y[2]
71 x, y, z = [], [], [] # type: (List[float], List[float], List[BB])
72 for zi in z:
73 #? BB()
74 zi
75
76 x = [
77 1,
78 2,
79 ] # type: List[str]
80
81 #? str()
82 x[1]
83
84
85 for bar in foo(): # type: str
86 #? str()
87 bar
88
89 for bar, baz in foo(): # type: int, float
90 #? int()
91 bar
92 #? float()
93 baz
94
95 for bar, baz in foo():
96 # type: str, str
97 """ type hinting on next line should not work """
98 #?
99 bar
100 #?
101 baz
102
103 with foo(): # type: int
104 ...
105
106 with foo() as f: # type: str
107 #? str()
108 f
109
110 with foo() as f:
111 # type: str
112 """ type hinting on next line should not work """
113 #?
114 f
115
116 aaa = some_extremely_long_function_name_that_doesnt_leave_room_for_hints() \
117 # type: float # We should be able to put hints on the next line with a \
118 #? float()
119 aaa
120
121 # Test instance methods
122 class Dog:
123 def __init__(self, age, friends, name):
124 # type: (int, List[Tuple[str, Dog]], str) -> None
125 #? int()
126 self.age = age
127 self.friends = friends
128
129 #? Dog()
130 friends[0][1]
131
132 #? str()
133 self.name = name
134
135 def friend_for_name(self, name):
136 # type: (str) -> Dog
137 for (friend_name, friend) in self.friends:
138 if friend_name == name:
139 return friend
140 raise ValueError()
141
142 def bark(self):
143 pass
144
145 buddy = Dog(UNKNOWN_NAME1, UNKNOWN_NAME2, UNKNOWN_NAME3)
146 friend = buddy.friend_for_name('buster')
147 # type of friend is determined by function return type
148 #! 9 ['def bark']
149 friend.bark()
150
151 friend = buddy.friends[0][1]
152 # type of friend is determined by function parameter type
153 #! 9 ['def bark']
154 friend.bark()
155
156 # type is determined by function parameter type following nested generics
157 #? str()
158 friend.name
159
160 # Mypy comment describing function return type.
161 def annot():
162 # type: () -> str
163 pass
164
165 #? str()
166 annot()
167
168 # Mypy variable type annotation.
169 x = UNKNOWN_NAME2 # type: str
170
171 #? str()
172 x
173
174 class Cat(object):
175 def __init__(self, age, friends, name):
176 # type: (int, List[Dog], str) -> None
177 self.age = age
178 self.friends = friends
179 self.name = name
180
181 cat = Cat(UNKNOWN_NAME4, UNKNOWN_NAME5, UNKNOWN_NAME6)
182 #? str()
183 cat.name
184
185
186 # Check potential errors
187 def x(a, b):
188 # type: ([) -> a
189 #?
190 a
191 def x(a, b):
192 # type: (1) -> a
193 #?
194 a
195 def x(a, b, c):
196 # type: (str) -> a
197 #?
198 b
199 #?
200 c