Skip to content

Commit 929ec19

Browse files
authored
fix E711 none-comparison (#2469)
1 parent 522d5df commit 929ec19

6 files changed

Lines changed: 15 additions & 16 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ ignore = [
160160
"F401", # https://docs.astral.sh/ruff/rules/unused-import/
161161
"F405", # https://docs.astral.sh/ruff/rules/undefined-local-with-import-star-usage/
162162
"E712", # https://docs.astral.sh/ruff/rules/true-false-comparison/
163-
"E711", # https://docs.astral.sh/ruff/rules/none-comparison/
164163
"E721", # https://docs.astral.sh/ruff/rules/type-comparison/
165164
"E722", # https://docs.astral.sh/ruff/rules/bare-except/
166165
"E741", # https://docs.astral.sh/ruff/rules/ambiguous-variable-name/

thunder/core/interpreter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ def get_python_tb(tb: list | TracebackType | None) -> list:
902902
return tb
903903

904904
res = []
905-
while tb != None:
905+
while tb is not None:
906906
res.append(PythonFrameWrapper(tb.tb_frame))
907907
tb = tb.tb_next
908908
return res
@@ -4283,7 +4283,7 @@ def _end_async_for_handler_3_10(
42834283
frame.interpreter_stack.pop() # we ignore that and assume == type(exc_value)
42844284
exc_value = frame.interpreter_stack.pop()
42854285
exc_traceback = frame.interpreter_stack.pop()
4286-
if exc_value != None:
4286+
if exc_value is not None:
42874287
exc_value.__traceback__ = exc_traceback
42884288
assert runtimectx.exception_stack
42894289
# CPython sets exc_info->exc_type/value/traceback
@@ -5787,7 +5787,7 @@ def do_raise(exc: Any = Py_NULL(), cause: Any = Py_NULL()) -> Literal[INTERPRETE
57875787
# Re-raise
57885788
assert runtimectx.exception_stack
57895789
value = runtimectx.exception_stack[0]
5790-
if value == None:
5790+
if value is None:
57915791
return do_raise(RuntimeError("No active exception to reraise"))
57925792
assert isinstance(value, BaseException)
57935793
# check for cause being PY_NULL? Python does not do this, but it would seem to be a bug
@@ -7307,7 +7307,7 @@ def _run_frame(
73077307
frame.interpreter_stack.pop() # we ignore that and assume == type(exc_value)
73087308
exc_value = frame.interpreter_stack.pop()
73097309
exc_traceback = frame.interpreter_stack.pop()
7310-
if exc_value != None:
7310+
if exc_value is not None:
73117311
exc_value.__traceback__ = exc_traceback
73127312
assert runtimectx.exception_stack
73137313
# CPython sets exc_info->exc_type/value/traceback

thunder/core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ def producers(trace_or_bsyms: TraceCtx | list[BoundSymbolInterface], *, _map_to_
10281028

10291029
for out in bsym.flat_proxy_outs:
10301030
# if a producer has already been traversed, skip
1031-
if producers.get(out, None) != None:
1031+
if producers.get(out, None) is not None:
10321032
continue
10331033

10341034
vout = variableify(out)

thunder/dynamo/report.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ def model(x):
371371

372372
folder = Path(folder)
373373
folder.mkdir(exist_ok=True, parents=True)
374-
if inputs == None:
374+
if inputs is None:
375375
inputs = self.example_input_meta
376376
has_cuda_args = any(hasattr(arg, "device") and arg.device.type == "cuda" for arg in inputs)
377377
has_requires_grad_args = any(hasattr(arg, "requires_grad") and arg.requires_grad for arg in inputs)
378378
torch_env, thunder_pkgs = get_env()
379379
readable = _readable(self.graph, "DynamoModule", print_output=False)
380380
# The packages that are likely to be used by the code generated from the Torch GraphModule
381381
torch_import_str = "\n".join([v.import_str for v in torch.fx.graph._custom_builtins.values()])
382-
import_str = "" if import_str == None else "\n".join(import_str)
382+
import_str = "" if import_str is None else "\n".join(import_str)
383383
input_str = textwrap.indent(self._get_input_str(folder, inputs, serialize_inputs), " ")
384384
call_bench_str = f"benchmark_for_compute_type(compute_type, benchmark, compiled_model, inputs, {{}}, has_cuda={True if has_cuda_args else False})"
385385
compute_type_decorator = (
@@ -502,7 +502,7 @@ def write_repro(
502502
"""
503503
folder = Path(folder)
504504
folder.mkdir(exist_ok=True, parents=True)
505-
if inputs == None:
505+
if inputs is None:
506506
inputs = self.example_input_meta
507507
code_str = self._get_repro_code(folder, compile_fn, None, serialize_inputs, inputs)
508508
comment_str = self._get_comment_str(extra_comment_str)
@@ -602,7 +602,7 @@ def write_benchmark(
602602
"""
603603
folder = Path(folder)
604604
folder.mkdir(exist_ok=True, parents=True)
605-
if inputs == None:
605+
if inputs is None:
606606
inputs = self.example_input_meta
607607
forward_only = not any(hasattr(arg, "requires_grad") and arg.requires_grad for arg in inputs)
608608
code_str = self._get_repro_code(folder, compile_fn, time_fn, serialize_inputs, inputs)
@@ -923,7 +923,7 @@ def write_nvfuser_benchmark(self, folder, time_fn: TimerInterface, file_name=Non
923923
print(measurement)
924924
{comment_str}
925925
"""
926-
if file_name == None:
926+
if file_name is None:
927927
file_name = f"{self.name}_benchmark_nvfuser.py"
928928
with open(folder / file_name, "w") as f:
929929
print(code_str, file=f)
@@ -936,7 +936,7 @@ def write_nvfuser_repro(self, folder, file_name=None):
936936
comment_str = f'"""\n{self.nvfusion_bsym}\n"""'
937937
repro_code_str = f"{repro_code_str}\n{comment_str}"
938938

939-
if file_name == None:
939+
if file_name is None:
940940
file_name = f"{self.name}_repro_nvfuser.py"
941941
with open(folder / file_name, "w") as f:
942942
print(repro_code_str, file=f)
@@ -966,7 +966,7 @@ def write_inductor_repro(self, folder: PathLike, file_name=None):
966966
code_str = f"""{code_str}
967967
out = torch_compiled_callable(*inputs)
968968
"""
969-
if file_name == None:
969+
if file_name is None:
970970
file_name = f"{self.name}_repro_inductor.py"
971971
with open(folder / file_name, "w") as f:
972972
f.write(code_str)
@@ -982,7 +982,7 @@ def write_inductor_benchmark(self, folder: PathLike, time_fn: TimerInterface, fi
982982
measurement = {time_fn.to_source("torch_compiled_callable", "inputs")}
983983
print(measurement)
984984
"""
985-
if file_name == None:
985+
if file_name is None:
986986
file_name = f"{self.name}_benchmark_inductor.py"
987987
with open(folder / file_name, "w") as f:
988988
f.write(code_str)

thunder/tests/test_dynamo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ def test_get_example_input_tensor_metadata():
10761076

10771077
t0 = torch.randn((5, 10), device="meta")
10781078
meta_t0 = _get_example_input_tensor_metadata(t0)
1079-
assert meta_t0.min_val == None and meta_t0.max_val == None and meta_t0.device.type == "meta"
1079+
assert meta_t0.min_val is None and meta_t0.max_val is None and meta_t0.device.type == "meta"
10801080
t0_str = arg_like_tensor(meta_t0)
10811081
assert (
10821082
t0_str

thunder/torch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5660,7 +5660,7 @@ def interpolate(
56605660
utils.check(a.ndim >= 3, lambda: f"Expected {a.ndim=} >= 3")
56615661
utils.check(a.numel() > 0, lambda: f"Expected {a.numel=} to be greater than 0")
56625662
utils.check(
5663-
align_corners == None,
5663+
align_corners is None,
56645664
lambda: "Thunder does not yet support 'align_corners'.",
56655665
exception_type=NotImplementedError,
56665666
)

0 commit comments

Comments
 (0)