Skip to content

Commit 3443627

Browse files
Revert "[BE]: Enable RUFF TRY400 rule - log.exception (pytorch#153473)"
This reverts commit 4f4ecc5. Reverted pytorch#153473 on behalf of https://github.com/jeanschmidt due to seems to have broken internal signals, @albanD may I count on you to help the author merge his PR? D74837988 ([comment](pytorch#153473 (comment)))
1 parent 86c6f71 commit 3443627

File tree

23 files changed

+46
-51
lines changed

23 files changed

+46
-51
lines changed

.flake8

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ ignore =
1616
# these ignores are from flake8-comprehensions; please fix!
1717
C407,
1818
# these ignores are from flake8-logging-format; please fix!
19-
G100,G101,G200,
20-
# G201 replaced by LOG400 in ruff
21-
G201,
19+
G100,G101,G200
2220
# these ignores are from flake8-simplify. please fix or ignore with commented reason
2321
SIM105,SIM108,SIM110,SIM111,SIM113,SIM114,SIM115,SIM116,SIM117,SIM118,SIM119,SIM12,
2422
# SIM104 is already covered by pyupgrade ruff

.github/scripts/runner_determinator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,9 @@ def main() -> None:
623623
is_canary,
624624
)
625625

626-
except Exception:
627-
log.exception(
628-
"Failed to get issue. Defaulting to Meta runners and no experiments."
626+
except Exception as e:
627+
log.error(
628+
f"Failed to get issue. Defaulting to Meta runners and no experiments. Exception: {e}"
629629
)
630630

631631
set_github_output(GH_OUTPUT_KEY_LABEL_TYPE, runner_label_prefix)

benchmarks/dynamo/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,8 +1700,8 @@ def maybe_snapshot_memory(should_snapshot_memory, suffix):
17001700
f"{output_filename.rstrip('.csv')}_{suffix}.pickle",
17011701
)
17021702
)
1703-
except Exception:
1704-
log.exception("Failed to save memory snapshot")
1703+
except Exception as e:
1704+
log.error("Failed to save memory snapshot, %s", e)
17051705

17061706
torch.cuda.memory._record_memory_history(enabled=None)
17071707

@@ -2742,7 +2742,7 @@ def minify_model(
27422742
try:
27432743
shutil.move("repro.py", f"{repro_dir}/{name}_repro.py")
27442744
except OSError:
2745-
log.exception("Could not find repro script for model %s", name)
2745+
log.error("Could not find repro script for model %s", name)
27462746
else:
27472747
log.info(
27482748
"Repro script for model %s with minified graph saved to %s",

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ select = [
197197
"TC",
198198
"TRY002", # ban vanilla raise (todo fix NOQAs)
199199
"TRY203",
200-
"TRY400", # use logging.exception
201200
"TRY401", # verbose-log-message
202201
"UP",
203202
"YTT",

tools/packaging/split_wheel.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,11 @@ def requirements_installed() -> bool:
4747

4848
return True
4949
except ImportError:
50-
logger.error( # noqa: TRY400
51-
"Requirements not installed, run the following command to install:",
52-
exc_info=False,
50+
logger.error(
51+
"Requirements not installed, run the following command to install:"
5352
)
54-
logger.error( # noqa: TRY400
55-
" > %s -m pip install -r %s/requirements.txt",
56-
sys.executable,
57-
ROOT_PATH,
58-
exc_info=False,
53+
logger.error(
54+
" > %s -m pip install -r %s/requirements.txt", sys.executable, ROOT_PATH
5955
)
6056
return False
6157

torch/_dynamo/repro/after_aot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def debug_wrapper(
138138
example_inputs,
139139
compiler_name,
140140
)
141-
log.exception("CompilerError")
141+
log.error("CompilerError")
142142
raise
143143

144144
# We may run regular PyTorch compute that may trigger Dynamo, do NOT

torch/_dynamo/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ def torchscript(model, example_inputs, verbose=False):
21482148
if verbose:
21492149
log.exception("jit error")
21502150
else:
2151-
log.error("Both torch.jit.trace and torch.jit.script failed") # noqa: TRY400
2151+
log.error("Both torch.jit.trace and torch.jit.script failed")
21522152
return None
21532153

21542154

torch/_guards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def create(self, builder: GuardBuilderBase):
359359
except Exception:
360360
log.exception("Error while creating guard:\n%s", str(self).rstrip())
361361
if self.stack:
362-
log.error("Created at:\n%s", "".join(self.stack.format()[-4:]).rstrip()) # noqa: TRY400
362+
log.error("Created at:\n%s", "".join(self.stack.format()[-4:]).rstrip())
363363
raise
364364

365365
def is_specialized_nn_module(self):

torch/_inductor/codegen/cuda/cuda_env.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def get_cuda_arch() -> Optional[str]:
2222
major, minor = torch.cuda.get_device_capability(0)
2323
return str(major * 10 + minor)
2424
return str(cuda_arch)
25-
except Exception:
26-
log.exception("Error getting cuda arch")
25+
except Exception as e:
26+
log.error("Error getting cuda arch: %s", e)
2727
return None
2828

2929

@@ -35,8 +35,8 @@ def get_cuda_version() -> Optional[str]:
3535
if cuda_version is None:
3636
cuda_version = torch.version.cuda
3737
return cuda_version
38-
except Exception:
39-
log.exception("Error getting cuda version")
38+
except Exception as e:
39+
log.error("Error getting cuda version: %s", e)
4040
return None
4141

4242

torch/_inductor/compile_fx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def _fx_compile_mode_default() -> tuple[FxCompileMode, bool]:
181181
import logging
182182

183183
log = logging.getLogger(__name__)
184-
log.error( # noqa: TRY400
184+
log.error(
185185
"Invalid value of %s for %s. Expected one of %s. Using default.",
186186
value,
187187
name,

0 commit comments

Comments
 (0)