[BE][Easy]: Apply RUF019: remove duplicate checks for dict access (#114478)
Applies RUF019 nightly preview rule to the codebase
Pull Request resolved: https://github.com/pytorch/pytorch/pull/114478
Approved by: https://github.com/mikaylagawarecki
diff --git a/test/optim/test_optim.py b/test/optim/test_optim.py
index e4c0475..ca955ad 100644
--- a/test/optim/test_optim.py
+++ b/test/optim/test_optim.py
@@ -851,7 +851,7 @@
st_max_mem, mt_max_mem = max_mems
intermediate_size = nparams * param.nelement() * param.element_size()
nintermediates = 1 # we expect a budget of 1 intermediate most of the time
- if (('capturable' in kwargs_with_flags and kwargs_with_flags['capturable']) or
+ if (kwargs_with_flags.get('capturable') or
optimizer_constructor.__name__ in ["Adadelta", "ASGD"]):
# with capturable in Adam(W), we have 2 extra intermediates for the bias_corrections
# with Adadelta, we have 2 extra for (acc_delta + eps) and (square_avg + eps)
diff --git a/torch/jit/_script.py b/torch/jit/_script.py
index dbbdf77..5e29c43 100644
--- a/torch/jit/_script.py
+++ b/torch/jit/_script.py
@@ -454,7 +454,7 @@
self.__dict__["_initializing"] = False
def __getattr__(self, attr):
- if "_initializing" in self.__dict__ and self.__dict__["_initializing"]:
+ if self.__dict__.get("_initializing"):
return super().__getattr__(attr) # type: ignore[misc]
if attr in self._props:
@@ -463,7 +463,7 @@
return getattr(self._c, attr)
def __setattr__(self, attr, value):
- if "_initializing" in self.__dict__ and self.__dict__["_initializing"]:
+ if self.__dict__.get("_initializing"):
return super().__setattr__(attr, value)
if attr in self._props: