Skip to content

Commit 22e943c

Browse files
authored
Remove E741 from ruff lint ignore rules (#2601)
1 parent 5cde18a commit 22e943c

17 files changed

+284
-283
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ ignore = [
161161
"E712", # https://docs.astral.sh/ruff/rules/true-false-comparison/
162162
"E721", # https://docs.astral.sh/ruff/rules/type-comparison/
163163
"E722", # https://docs.astral.sh/ruff/rules/bare-except/
164-
"E741", # https://docs.astral.sh/ruff/rules/ambiguous-variable-name/
165164
]
166165

167166
[tool.ruff.lint.per-file-ignores]

thunder/clang/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@ def _basic_indexing(a: TensorLike, /, key) -> TensorLike:
453453

454454
# Handles numbers and slices
455455
squeeze_dims = []
456-
for idx, (l, x) in enumerate(zip(a.shape, key)):
456+
for idx, (length, x) in enumerate(zip(a.shape, key)):
457457
if isinstance(x, slice):
458458
start = x.start if x.start is not None else 0
459-
stop = x.stop if x.stop is not None else l
459+
stop = x.stop if x.stop is not None else length
460460
step = x.step if x.step is not None else 1
461461

462462
# Tests for negative step (PyTorch doesn't allow step < 1)
@@ -465,11 +465,11 @@ def _basic_indexing(a: TensorLike, /, key) -> TensorLike:
465465
# Canonicalizes start and stop (allowing for values like -1)
466466
# NOTE: canonicalization is custom because start and stop beyond the length are allowed
467467
if start < 0:
468-
start = start + l
469-
utils.check(start >= 0, lambda: f"start={x.start} is not a valid index for length {l}")
468+
start = start + length
469+
utils.check(start >= 0, lambda: f"start={x.start} is not a valid index for length {length}")
470470
if stop < 0:
471-
stop = stop + l
472-
utils.check(stop >= 0, lambda: f"end={x.stop} is not a valid index for length {l}")
471+
stop = stop + length
472+
utils.check(stop >= 0, lambda: f"end={x.stop} is not a valid index for length {length}")
473473

474474
# Handles start > stop, which occurs with slices like 3:1:1
475475
# NOTE Because step is always strictly positive, it's sufficient to check start
@@ -480,19 +480,19 @@ def _basic_indexing(a: TensorLike, /, key) -> TensorLike:
480480

481481
# Handles overflow
482482
# NOTE This is a little odd, but we just want the slice to be zero
483-
if start >= l:
483+
if start >= length:
484484
start = 0
485485
stop = 0
486486

487-
if stop >= l:
488-
stop = l
487+
if stop >= length:
488+
stop = length
489489

490490
start_indices.append(start)
491491
end_indices.append(stop)
492492
strides.append(step)
493493
elif isinstance(x, (Number, NumberProxy)):
494494
# NOTE Numbers must be valid indices after canonicalization, unlike start and stop
495-
x = utils.canonicalize_dim(l, x)
495+
x = utils.canonicalize_dim(length, x)
496496
start_indices.append(x)
497497
end_indices.append(x + 1)
498498
strides.append(1)
@@ -504,7 +504,7 @@ def _basic_indexing(a: TensorLike, /, key) -> TensorLike:
504504
# performance optimization; check if we need slicing
505505
if (
506506
all([x == 0 for x in start_indices])
507-
and all([x == l for x, l in zip(end_indices, a.shape)])
507+
and all([x == length for x, length in zip(end_indices, a.shape)])
508508
and all([x == 1 for x in strides])
509509
and len(squeeze_dims) == 0
510510
):
@@ -804,11 +804,11 @@ def reshape(a: TensorLike, shape: Sequence[int]) -> TensorLike:
804804
# Checks for -1 marker value
805805
numel = 1
806806
neg_one_idx = None
807-
for idx, l in enumerate(shape):
808-
if l >= 0:
809-
numel *= l
807+
for idx, length in enumerate(shape):
808+
if length >= 0:
809+
numel *= length
810810
else:
811-
utils.check(l == -1, "Found a negative dimension length {l} in shape={shape}!")
811+
utils.check(length == -1, "Found a negative dimension length {length} in shape={shape}!")
812812
utils.check(neg_one_idx is None, "Found two -1 markers in shape={shape}!")
813813
neg_one_idx = idx
814814

thunder/core/baseutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ def check_valid_shape(shape: tuple[int, NumberProxy, ...] | list[int]):
193193

194194
check_type(shape, (tuple, list))
195195

196-
for l in shape:
197-
check_valid_length(l)
196+
for length in shape:
197+
check_valid_length(length)
198198

199199

200200
#

thunder/core/interpreter.py

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,21 @@ def unwrap(self):
193193
# Note: Use these with care!
194194
# In some situations - in particular *args/**kwargs, Python creates tuples and dicts for us,
195195
# these functions are intended to do the appropriate wrapping for them.
196-
def wrap_args_from_list(l): # returns a new list!
197-
res = [_interpret_call(lambda l, i: l[i], l, wrap_const(i)) for i in range(len(unwrap(l)))]
196+
def wrap_args_from_list(lst): # returns a new list!
197+
res = [_interpret_call(lambda seq, i: seq[i], lst, wrap_const(i)) for i in range(len(unwrap(lst)))]
198198
return res
199199

200200

201201
def wrap_kwargs_from_dict(d): # returns a new dict
202202
return {k: _interpret_call(lambda d, k: d[k], d, wrap_const(k)) for k in unwrap(d)}
203203

204204

205-
def wrapped_build_tuple(l: Sequence[WrappedValue]) -> WrappedValue:
206-
assert all(isinstance(v, WrappedValue) for v in l)
207-
if l:
208-
pr = ProvenanceRecord(PseudoInst.BUILD_TUPLE, inputs=[v.provenance for v in l][::-1]) # other inst?
209-
out = wrap(tuple(v.value for v in l), provenance=pr)
210-
out.item_wrappers = list(l)
205+
def wrapped_build_tuple(seq: Sequence[WrappedValue]) -> WrappedValue:
206+
assert all(isinstance(v, WrappedValue) for v in seq)
207+
if seq:
208+
pr = ProvenanceRecord(PseudoInst.BUILD_TUPLE, inputs=[v.provenance for v in seq][::-1]) # other inst?
209+
out = wrap(tuple(v.value for v in seq), provenance=pr)
210+
out.item_wrappers = list(seq)
211211
else:
212212
# Note: if we revisit returning const here instead of an empty tuple from BUILD_TUPLE, we need to add this to wrap_aergs
213213
out = wrap_const(())
@@ -336,36 +336,36 @@ def wrap_binary_subscr(uvalue, obj, key):
336336
return wrap(uvalue, provenance=ProvenanceRecord(PseudoInst.BINARY_SUBSCR, inputs=[obj.provenance, key.provenance]))
337337

338338

339-
def populate_item_wrappers(l):
339+
def populate_item_wrappers(obj):
340340
ctx: InterpreterCompileCtx = get_interpretercompilectx()
341341
if not ctx._with_provenance_tracking:
342342
return
343343

344-
assert isinstance(l, WrappedValue)
344+
assert isinstance(obj, WrappedValue)
345345
# to do: generalize
346-
if wrapped_isinstance(l, (list, tuple)):
347-
if l.item_wrappers is None:
348-
l.item_wrappers = [None for _ in range(len(l.value))]
349-
assert isinstance(l.item_wrappers, list)
350-
assert len(l.value) == len(l.item_wrappers), f"{len(l.value)=} {len(l.item_wrappers)=}"
351-
352-
for i, v in enumerate(l.value):
353-
if l.item_wrappers[i] is None:
354-
wv = wrap_binary_subscr(v, l, i)
355-
l.item_wrappers[i] = wv
346+
if wrapped_isinstance(obj, (list, tuple)):
347+
if obj.item_wrappers is None:
348+
obj.item_wrappers = [None for _ in range(len(obj.value))]
349+
assert isinstance(obj.item_wrappers, list)
350+
assert len(obj.value) == len(obj.item_wrappers), f"{len(obj.value)=} {len(obj.item_wrappers)=}"
351+
352+
for i, v in enumerate(obj.value):
353+
if obj.item_wrappers[i] is None:
354+
wv = wrap_binary_subscr(v, obj, i)
355+
obj.item_wrappers[i] = wv
356356
return
357357

358-
if wrapped_isinstance(l, dict):
359-
assert isinstance(l.item_wrappers, dict)
360-
for k, v in l.value.items():
361-
if k not in l.item_wrappers:
358+
if wrapped_isinstance(obj, dict):
359+
assert isinstance(obj.item_wrappers, dict)
360+
for k, v in obj.value.items():
361+
if k not in obj.item_wrappers:
362362
wk = wrap_const(k)
363-
wv = wrap_binary_subscr(v, l, wk)
364-
l.item_wrappers[k] = wv
365-
l.key_wrappers[k] = wk # or have those from an iteration of the input?
363+
wv = wrap_binary_subscr(v, obj, wk)
364+
obj.item_wrappers[k] = wv
365+
obj.key_wrappers[k] = wk # or have those from an iteration of the input?
366366
return
367367

368-
raise NotImplementedError(f"populate item wrappers for {type(l.value)}")
368+
raise NotImplementedError(f"populate item wrappers for {type(obj.value)}")
369369

370370

371371
#
@@ -883,15 +883,15 @@ def __init__(self, frame: FrameType):
883883

884884
def format_with_source(self):
885885
assert self.positions is not None, self
886-
l = []
887-
l.append(f" in {self.qualname} in file: {self.code.co_filename}, line {self.positions.lineno}:")
886+
lst = []
887+
lst.append(f" in {self.qualname} in file: {self.code.co_filename}, line {self.positions.lineno}:")
888888
if self.code.co_filename:
889889
ls = linecache.getlines(self.code.co_filename)
890890
lineno = self.positions.lineno
891891
if lineno is None:
892892
lineno = self.code.co_firstlineno
893-
l.append(" " + ls[max(lineno - 1, 0)].rstrip())
894-
return os.linesep.join(l)
893+
lst.append(" " + ls[max(lineno - 1, 0)].rstrip())
894+
return os.linesep.join(lst)
895895

896896
def get_or_make_python_frame(self) -> FrameType:
897897
return self.frame
@@ -980,10 +980,10 @@ def recurse_str(self):
980980
inputs = [recurse_str(i) for i in self.inputs]
981981
inputs_str = ", ".join(inputs)
982982
counter += 1
983-
l = f" i{counter} = {self.inst}({inputs_str})"
983+
out_item = f" i{counter} = {self.inst}({inputs_str})"
984984
if self.output_idx != 0 or self.output_key is not None:
985-
l += "# with output spec"
986-
out.append(l)
985+
out_item += "# with output spec"
986+
out.append(out_item)
987987
res = f"i{counter}"
988988
known[self] = res
989989
return res
@@ -1034,11 +1034,11 @@ def unpack_provenance_record(self, wrapped_value, key: int | slice | None = None
10341034
return wrapped_value
10351035
# key=None is pop
10361036
if isinstance(key, slice):
1037-
l = len(self._stack)
1037+
length = len(self._stack)
10381038
if key.start is not None:
10391039
start = key.start
10401040
else:
1041-
start = -l
1041+
start = -length
10421042
assert start < 0
10431043
if key.step is not None:
10441044
step = key.step
@@ -1156,18 +1156,18 @@ def nexti(self, inst: dis.Instruction):
11561156
def format_with_source(self) -> str:
11571157
# todo: multiple lines in positions, underline, indent
11581158
assert self.positions is not None, self
1159-
l = []
1160-
l.append(f" in {self.qualname} in file: {self.code.co_filename}, line {self.positions.lineno}:")
1159+
lines = []
1160+
lines.append(f" in {self.qualname} in file: {self.code.co_filename}, line {self.positions.lineno}:")
11611161
if self.code.co_filename:
11621162
ls = linecache.getlines(self.code.co_filename)
11631163
if ls:
11641164
lineno = self.positions.lineno
11651165
if lineno is None:
11661166
lineno = self.code.co_firstlineno
1167-
l.append(" " + ls[max(lineno - 1, 0)].rstrip())
1167+
lines.append(" " + ls[max(lineno - 1, 0)].rstrip())
11681168
else:
1169-
l.append(" <unavailable>")
1170-
return os.linesep.join(l)
1169+
lines.append(" <unavailable>")
1170+
return os.linesep.join(lines)
11711171

11721172
def get_localsplus_name(self, idx: int) -> str:
11731173
if sys.version_info < (3, 11):
@@ -1194,7 +1194,7 @@ def get_or_make_python_frame(self) -> FrameType:
11941194
name = self.code.co_name
11951195
qualname = self.qualname
11961196

1197-
def get_frame(l, rel_lineno, filename, firstlineno, name, qualname):
1197+
def get_frame(container, rel_lineno, filename, firstlineno, name, qualname):
11981198
def fn():
11991199
pass
12001200

@@ -1219,7 +1219,7 @@ def fn():
12191219
assert tb is not None
12201220
while tb.tb_next is not None:
12211221
tb = tb.tb_next
1222-
l.append(tb.tb_frame)
1222+
container.append(tb.tb_frame)
12231223

12241224
# we run the getting of the frame in a separate thread because
12251225
# we want to avoid having f_back pointing to the function
@@ -2133,15 +2133,15 @@ class SequenceWrapperMethods(WrappedValue):
21332133
def __init__(self, iterable=(), /):
21342134
if iterable == ():
21352135
iterable = wrap_const(())
2136-
l = wrap_const([])
2137-
assert l.item_wrappers is not None
2136+
wrapped_list = wrap_const([])
2137+
assert wrapped_list.item_wrappers is not None
21382138

2139-
res = _interpret_call(list.extend, l, iterable)
2139+
res = _interpret_call(list.extend, wrapped_list, iterable)
21402140
if res is INTERPRETER_SIGNALS.EXCEPTION_RAISED:
21412141
return res
21422142
assert type(self.value) is self.python_typ
2143-
self.value[:] = l.value[:]
2144-
self.item_wrappers = l.item_wrappers[:]
2143+
self.value[:] = wrapped_list.value[:]
2144+
self.item_wrappers = wrapped_list.item_wrappers[:]
21452145
return wrap_const(None)
21462146

21472147
def __getitem__(self, idx, /):
@@ -2195,10 +2195,10 @@ def __mul__(self, n, /):
21952195
self.track_items()
21962196

21972197
def impl(self, n):
2198-
l = []
2198+
seq = []
21992199
for _ in range(n):
2200-
l.extend(self)
2201-
return type(self)(l)
2200+
seq.extend(self)
2201+
return type(self)(seq)
22022202

22032203
return _interpret_call(impl, self, n)
22042204

@@ -2336,9 +2336,9 @@ def extend(self, iterable, /):
23362336

23372337
if not isinstance(iterable.value, (tuple, list)):
23382338

2339-
def impl(l, iterable):
2339+
def impl(seq, iterable):
23402340
for i in iterable:
2341-
l.append(i)
2341+
seq.append(i)
23422342

23432343
res = _interpret_call(impl, self, iterable)
23442344
assert len(self.value) == len(self.item_wrappers)
@@ -2392,7 +2392,7 @@ def pop(self, index=-1, /):
23922392
if uindex < -len(uself) or uindex >= len(uself):
23932393
return do_raise(IndexError("pop index out of range"))
23942394

2395-
res = _interpret_call(lambda l, i: l[i], self, index)
2395+
res = _interpret_call(lambda seq, i: seq[i], self, index)
23962396

23972397
assert res is not INTERPRETER_SIGNALS.EXCEPTION_RAISED
23982398

@@ -2873,7 +2873,7 @@ def _tuple_new_provenance_tracking_lookaside(cls, iterable=(), /):
28732873
item_wrappers = []
28742874
# TODO: investigate why just taking the wrappers will break test_interpreter.py::test_module_hooks
28752875
for i in range(len(iterable.value)):
2876-
item_wrappers.append(_interpret_call(lambda l, i: l[i], iterable, wrap_const(i)))
2876+
item_wrappers.append(_interpret_call(lambda seq, i: seq[i], iterable, wrap_const(i)))
28772877
else:
28782878
iterator = _interpret_call(iter, iterable)
28792879
if iterator is INTERPRETER_SIGNALS.EXCEPTION_RAISED:
@@ -4818,14 +4818,14 @@ def _list_append_handler(inst: dis.Instruction, /, stack: InterpreterStack, **kw
48184818

48194819
# NOTE Doesn't pop the list that's extended
48204820
tos = stack.pop_wrapped()
4821-
l: list = stack.getitem_wrapped(-i)
4821+
lst: list = stack.getitem_wrapped(-i)
48224822

4823-
assert wrapped_isinstance(l, list)
4823+
assert wrapped_isinstance(lst, list)
48244824

4825-
def impl(l, tos):
4826-
l.append(tos)
4825+
def impl(lst, tos):
4826+
lst.append(tos)
48274827

4828-
res = _interpret_call(impl, l, tos)
4828+
res = _interpret_call(impl, lst, tos)
48294829
if res is INTERPRETER_SIGNALS.EXCEPTION_RAISED:
48304830
return res
48314831

@@ -4838,11 +4838,11 @@ def _list_extend_handler(inst: dis.Instruction, /, stack: InterpreterStack, **kw
48384838

48394839
# NOTE Doesn't pop the list that's extended
48404840
tos = stack.pop_wrapped()
4841-
l: list = stack.getitem_wrapped(-i)
4841+
lst: list = stack.getitem_wrapped(-i)
48424842

48434843
# NOTE tos does not have to be a list
4844-
assert wrapped_isinstance(l, list)
4845-
res = _interpret_call(lambda l1, l2: l1.extend(l2), l, tos)
4844+
assert wrapped_isinstance(lst, list)
4845+
res = _interpret_call(lambda l1, l2: l1.extend(l2), lst, tos)
48464846

48474847
if res is INTERPRETER_SIGNALS.EXCEPTION_RAISED:
48484848
return res

thunder/core/jit_ext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,11 +1842,11 @@ def from_provenance(provenance, *, new_output=False):
18421842
return p
18431843

18441844
with tracectx(prologue_trace):
1845-
for n, l in (("args", len(args)), ("kwargs", len(kwargs))):
1845+
for n, length in (("args", len(args)), ("kwargs", len(kwargs))):
18461846
output = Proxy(name=n)
18471847
bsym = prims.unpack_trivial.bind(output, output=output, name=n)
18481848
prologue_trace.bound_symbols.append(bsym)
1849-
bsym = prims.check_len.bind(output, l, output=None)
1849+
bsym = prims.check_len.bind(output, length, output=None)
18501850
prologue_trace.bound_symbols.append(bsym)
18511851
if n == "args":
18521852
pro_args_proxy = output

0 commit comments

Comments
 (0)