154 """ |
154 """ |
155 prefix = "" |
155 prefix = "" |
156 if isinstance(node, ast.Attribute): |
156 if isinstance(node, ast.Attribute): |
157 try: |
157 try: |
158 val = deepgetattr(node, 'value.id') |
158 val = deepgetattr(node, 'value.id') |
159 if val in aliases: |
159 prefix = ( |
160 prefix = aliases[val] |
160 aliases[val] if val in aliases |
161 else: |
161 else deepgetattr(node, 'value.id') |
162 prefix = deepgetattr(node, 'value.id') |
162 ) |
163 except Exception: # secok |
163 except Exception: # secok |
164 # We can't get the fully qualified name for an attr, just return |
164 # We can't get the fully qualified name for an attr, just return |
165 # its base name. |
165 # its base name. |
166 pass |
166 pass |
167 |
167 |
193 @param node node to extract a line range from |
193 @param node node to extract a line range from |
194 @type ast.AST |
194 @type ast.AST |
195 @return list containing the line number range |
195 @return list containing the line number range |
196 @rtype list of int |
196 @rtype list of int |
197 """ |
197 """ |
198 strip = {"body": None, "orelse": None, |
198 strip = { |
199 "handlers": None, "finalbody": None} |
199 "body": None, |
200 for key in strip.keys(): |
200 "orelse": None, |
|
201 "handlers": None, |
|
202 "finalbody": None |
|
203 } |
|
204 for key in strip: |
201 if hasattr(node, key): |
205 if hasattr(node, key): |
202 strip[key] = getattr(node, key) |
206 strip[key] = getattr(node, key) |
203 node.key = [] |
207 node.key = [] |
204 |
208 |
205 lines_min = 9999999999 |
209 lines_min = 9999999999 |
207 for n in ast.walk(node): |
211 for n in ast.walk(node): |
208 if hasattr(n, 'lineno'): |
212 if hasattr(n, 'lineno'): |
209 lines_min = min(lines_min, n.lineno) |
213 lines_min = min(lines_min, n.lineno) |
210 lines_max = max(lines_max, n.lineno) |
214 lines_max = max(lines_max, n.lineno) |
211 |
215 |
212 for key in strip.keys(): |
216 for key in strip: |
213 if strip[key] is not None: |
217 if strip[key] is not None: |
214 node.key = strip[key] |
218 node.key = strip[key] |
215 |
219 |
216 if lines_max > -1: |
220 if lines_max > -1: |
217 return list(range(lines_min, lines_max + 1)) |
221 return list(range(lines_min, lines_max + 1)) |