Skip to content

Commit 521a850

Browse files
committed
Rename variable to something more appropriate
1 parent ecf3c64 commit 521a850

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

trepan/processor/location.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def resolve_location(proc, location) -> Optional[Location]:
5454
pass
5555

5656
location_method = location.method
57-
filename = lineno = mod_func = None
57+
filename = lineno = mod_or_func_or_code = None
5858
if location_method:
5959
# Validate arguments that can't be done in parsing
6060
if location_method == "<module>":
@@ -73,16 +73,16 @@ def resolve_location(proc, location) -> Optional[Location]:
7373
if len(modules):
7474
# There is at least one matching module. (They all
7575
# should be the same.)
76-
mod_func = modules[0]
76+
mod_or_func_or_code = modules[0]
7777
else:
7878
proc.errmsg(f"Cannot resolve <module> from a path {filename}")
7979
return INVALID_LOCATION
8080

81-
if mod_func is None:
81+
if mod_or_func_or_code is None:
8282
# [1] DRY similar code [2] below
8383
msg = f"Object {location_method} is not known yet as a function."
8484
try:
85-
mod_func = eval(location_method, g, locals_dict)
85+
mod_or_func_or_code = eval(location_method, g, locals_dict)
8686
except Exception:
8787
proc.errmsg(msg)
8888
split_names = location_method.split(".")
@@ -98,45 +98,45 @@ def resolve_location(proc, location) -> Optional[Location]:
9898
# trepan-xpy() which has it's own type of compatible
9999
# Function, that would fail an `inspect.isfunction()`
100100
# test.
101-
if hasattr(mod_func, "__code__") or hasattr(mod_func, "im_func"):
101+
if hasattr(mod_or_func_or_code, "__code__") or hasattr(mod_or_func_or_code, "im_func"):
102102
offset = -1
103103
else:
104104
proc.errmsg(msg)
105105
return INVALID_LOCATION
106106
except Exception:
107107
proc.errmsg(msg)
108108
return INVALID_LOCATION
109-
filename = proc.core.canonic(mod_func.__code__.co_filename)
109+
filename = proc.core.canonic(mod_or_func_or_code.__code__.co_filename)
110110

111111
# FIXME: we may want to check lineno and
112112
# respect that in the future
113-
lineno = mod_func.__code__.co_firstlineno
113+
lineno = mod_or_func_or_code.__code__.co_firstlineno
114114

115115
elif location.path:
116116
filename = proc.core.canonic(location.path)
117117
lineno = location.line_number
118-
mod_func = None
118+
mod_or_func_or_code = None
119119
msg = f"{location.path} is not known as a file"
120120
if not osp.isfile(filename):
121121
# See if argument is a module
122122
try:
123-
mod_func = eval(location.path, g, locals_dict)
123+
mod_or_func_or_code = eval(location.path, g, locals_dict)
124124
except Exception:
125125
msg = f"Don't see '{location.path}' as a existing file or as an module"
126126
proc.errmsg(msg)
127127
return INVALID_LOCATION
128128
pass
129129
is_address = location.is_address
130-
if inspect.ismodule(mod_func):
131-
if hasattr(mod_func, "__file__"):
132-
filename = pyficache.resolve_name_to_path(mod_func.__file__)
130+
if inspect.ismodule(mod_or_func_or_code):
131+
if hasattr(mod_or_func_or_code, "__file__"):
132+
filename = pyficache.resolve_name_to_path(mod_or_func_or_code.__file__)
133133
filename = proc.core.canonic(filename)
134134
if not lineno:
135135
# use first line of module file
136136
lineno = 1
137137
offset = 0
138138
is_address = False
139-
return Location(filename, lineno, is_address, mod_func, offset)
139+
return Location(filename, lineno, is_address, mod_or_func_or_code, offset)
140140
else:
141141
msg = f"module '{location.path}' doesn't have a file associated with it"
142142

@@ -155,7 +155,7 @@ def resolve_location(proc, location) -> Optional[Location]:
155155
code_info, lineinfo = pyficache.code_line_info(filename, lineno)
156156
if lineinfo:
157157
offset = lineinfo[0].offsets[0]
158-
mod_func = code_info[lineinfo[0].name]
158+
mod_or_func_or_code = code_info[lineinfo[0].name]
159159
else:
160160
return INVALID_LOCATION
161161

@@ -167,26 +167,26 @@ def resolve_location(proc, location) -> Optional[Location]:
167167
filename = frame2file(proc.core, curframe, canonic=False)
168168
lineno = location.line_number
169169
is_address = location.is_address
170-
mod_func = curframe.f_code
170+
mod_or_func_or_code = curframe.f_code
171171
if offset is None:
172172
code_info, lineinfo = pyficache.code_line_info(filename, lineno, include_offsets=True)
173173
if lineinfo:
174174
offset = lineinfo[0].offsets[0]
175-
mod_func_name = lineinfo[0].name
176-
if mod_func.co_name != mod_func_name:
175+
mod_or_func_or_code_name = lineinfo[0].name
176+
if mod_or_func_or_code.co_name != mod_or_func_or_code_name:
177177
# Breakpoint is in a nested function/method.
178178
# Get new code object
179-
mod_func = code_info.get(mod_func_name, mod_func)
179+
mod_or_func_or_code = code_info.get(mod_or_func_or_code_name, mod_or_func_or_code)
180180
pass
181181
else:
182182
return INVALID_LOCATION
183183
elif location.offset is not None:
184184
filename = frame2file(proc.core, curframe, canonic=False)
185185
is_address = True
186186
lineno = None
187-
mod_func = None
187+
mod_or_func_or_code = None
188188
offset = location.offset
189-
return Location(filename, lineno, is_address, mod_func, offset)
189+
return Location(filename, lineno, is_address, mod_or_func_or_code, offset)
190190

191191

192192
def resolve_address_location(proc, location) -> Optional[Location]:
@@ -217,7 +217,7 @@ def resolve_address_location(proc, location) -> Optional[Location]:
217217
msg = f"Object {location.method} is not known yet as a function."
218218
# [2] DRY simlar code above [1]
219219
try:
220-
mod_func = eval(location.method, g, locals_dict)
220+
mod_or_func_or_code = eval(location.method, g, locals_dict)
221221
except Exception:
222222
split_names = location_method.split(".")
223223
if len(split_names) > 1:
@@ -227,43 +227,43 @@ def resolve_address_location(proc, location) -> Optional[Location]:
227227

228228
try:
229229
# Check if the converted string is a function or instance method
230-
if inspect.isfunction(mod_func) or hasattr(mod_func, "im_func"):
230+
if inspect.isfunction(mod_or_func_or_code) or hasattr(mod_or_func_or_code, "im_func"):
231231
pass
232232
else:
233233
proc.errmsg(msg)
234234
return INVALID_LOCATION
235235
except Exception:
236236
proc.errmsg(msg)
237237
return INVALID_LOCATION
238-
filename = proc.core.canonic(mod_func.func_code.co_filename)
238+
filename = proc.core.canonic(mod_or_func_or_code.func_code.co_filename)
239239
# FIXME: we may want to check offset and
240240
# respect that in the future
241241
offset = 0
242242
elif location.path:
243243
filename = proc.core.canonic(location.path)
244244
offset = location.line_number
245245
is_address = location.is_address
246-
mod_func = None
246+
mod_or_func_or_code = None
247247
msg = f"{location.path} is not known as a file"
248248
if not osp.isfile(filename):
249249
# See if argument is a module
250250
try:
251-
mod_func = eval(location.path, g, locals_dict)
251+
mod_or_func_or_code = eval(location.path, g, locals_dict)
252252
except Exception:
253253
msg = f"Don't see '{location.path}' as a existing file or as an module"
254254
proc.errmsg(msg)
255255
return INVALID_LOCATION
256256
pass
257257
is_address = location.is_address
258-
if inspect.ismodule(mod_func):
259-
if hasattr(mod_func, "__file__"):
260-
filename = pyficache.resolve_name_to_path(mod_func.__file__)
258+
if inspect.ismodule(mod_or_func_or_code):
259+
if hasattr(mod_or_func_or_code, "__file__"):
260+
filename = pyficache.resolve_name_to_path(mod_or_func_or_code.__file__)
261261
filename = proc.core.canonic(filename)
262262
if not offset:
263263
# use first offset of module file
264264
offset = 0
265265
is_address = True
266-
return Location(filename, offset, is_address, mod_func, offset)
266+
return Location(filename, offset, is_address, mod_or_func_or_code, offset)
267267
else:
268268
msg = f"module '{location.path}' doesn't have a file associated with it"
269269

@@ -280,14 +280,14 @@ def resolve_address_location(proc, location) -> Optional[Location]:
280280
filename = frame2file(proc.core, curframe, canonic=False)
281281
offset = location.line_number
282282
is_address = location.is_address
283-
mod_func = proc.list_object
283+
mod_or_func_or_code = proc.list_object
284284
else:
285285
proc.errmsg(
286286
f"Location {location} doesn't have enough information for a location."
287287
)
288288
return INVALID_LOCATION
289289

290-
return Location(filename, offset, is_address, mod_func, offset)
290+
return Location(filename, offset, is_address, mod_or_func_or_code, offset)
291291

292292

293293
# Demo it

0 commit comments

Comments
 (0)