17
17
def current_word (cursor_offset , line ):
18
18
"""the object.attribute.attribute just before or under the cursor"""
19
19
pos = cursor_offset
20
- matches = current_word_re .finditer (line )
21
20
start = pos
22
21
end = pos
23
22
word = None
24
- for m in matches :
23
+ for m in current_word_re . finditer ( line ) :
25
24
if m .start (1 ) < pos and m .end (1 ) >= pos :
26
25
start = m .start (1 )
27
26
end = m .end (1 )
@@ -36,8 +35,7 @@ def current_word(cursor_offset, line):
36
35
37
36
def current_dict_key (cursor_offset , line ):
38
37
"""If in dictionary completion, return the current key"""
39
- matches = current_dict_key_re .finditer (line )
40
- for m in matches :
38
+ for m in current_dict_key_re .finditer (line ):
41
39
if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
42
40
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
43
41
return None
@@ -48,8 +46,7 @@ def current_dict_key(cursor_offset, line):
48
46
49
47
def current_dict (cursor_offset , line ):
50
48
"""If in dictionary completion, return the dict that should be used"""
51
- matches = current_dict_re .finditer (line )
52
- for m in matches :
49
+ for m in current_dict_re .finditer (line ):
53
50
if m .start (2 ) <= cursor_offset and m .end (2 ) >= cursor_offset :
54
51
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
55
52
return None
@@ -84,9 +81,8 @@ def current_object(cursor_offset, line):
84
81
if match is None :
85
82
return None
86
83
start , end , word = match
87
- matches = current_object_re .finditer (word )
88
84
s = ""
89
- for m in matches :
85
+ for m in current_object_re . finditer ( word ) :
90
86
if m .end (1 ) + start < cursor_offset :
91
87
if s :
92
88
s += "."
@@ -132,8 +128,7 @@ def current_from_import_from(cursor_offset, line):
132
128
tokens = line .split ()
133
129
if not ("from" in tokens or "import" in tokens ):
134
130
return None
135
- matches = current_from_import_from_re .finditer (line )
136
- for m in matches :
131
+ for m in current_from_import_from_re .finditer (line ):
137
132
if (m .start (1 ) < cursor_offset and m .end (1 ) >= cursor_offset ) or (
138
133
m .start (2 ) < cursor_offset and m .end (2 ) >= cursor_offset
139
134
):
@@ -157,8 +152,10 @@ def current_from_import_import(cursor_offset, line):
157
152
match1 = current_from_import_import_re_2 .search (line [baseline .end () :])
158
153
if match1 is None :
159
154
return None
160
- matches = current_from_import_import_re_3 .finditer (line [baseline .end () :])
161
- for m in chain ((match1 ,), matches ):
155
+ for m in chain (
156
+ (match1 ,),
157
+ current_from_import_import_re_3 .finditer (line [baseline .end () :]),
158
+ ):
162
159
start = baseline .end () + m .start (1 )
163
160
end = baseline .end () + m .end (1 )
164
161
if start < cursor_offset and end >= cursor_offset :
@@ -179,8 +176,9 @@ def current_import(cursor_offset, line):
179
176
match1 = current_import_re_2 .search (line [baseline .end () :])
180
177
if match1 is None :
181
178
return None
182
- matches = current_import_re_3 .finditer (line [baseline .end () :])
183
- for m in chain ((match1 ,), matches ):
179
+ for m in chain (
180
+ (match1 ,), current_import_re_3 .finditer (line [baseline .end () :])
181
+ ):
184
182
start = baseline .end () + m .start (1 )
185
183
end = baseline .end () + m .end (1 )
186
184
if start < cursor_offset and end >= cursor_offset :
@@ -192,8 +190,7 @@ def current_import(cursor_offset, line):
192
190
193
191
def current_method_definition_name (cursor_offset , line ):
194
192
"""The name of a method being defined"""
195
- matches = current_method_definition_name_re .finditer (line )
196
- for m in matches :
193
+ for m in current_method_definition_name_re .finditer (line ):
197
194
if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
198
195
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
199
196
return None
@@ -204,8 +201,7 @@ def current_method_definition_name(cursor_offset, line):
204
201
205
202
def current_single_word (cursor_offset , line ):
206
203
"""the un-dotted word just before or under the cursor"""
207
- matches = current_single_word_re .finditer (line )
208
- for m in matches :
204
+ for m in current_single_word_re .finditer (line ):
209
205
if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
210
206
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
211
207
return None
@@ -229,8 +225,7 @@ def current_dotted_attribute(cursor_offset, line):
229
225
def current_expression_attribute (cursor_offset , line ):
230
226
"""If after a dot, the attribute being completed"""
231
227
# TODO replace with more general current_expression_attribute
232
- matches = current_expression_attribute_re .finditer (line )
233
- for m in matches :
228
+ for m in current_expression_attribute_re .finditer (line ):
234
229
if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
235
230
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
236
231
return None
0 commit comments