"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "67c3518f68d9129a1c429fd45659c7896c44e08e"
Commit bbb792d3 authored by Richard Barnes's avatar Richard Barnes Committed by Facebook GitHub Bot
Browse files

Replace hasattr with getattr in mobile-vision/d2go/d2go/utils/abnormal_checker.py

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/533

The pattern
```
X.Y if hasattr(X, "Y") else Z
```
can be replaced with
```
getattr(X, "Y", Z)
```

The [getattr](https://www.w3schools.com/python/ref_func_getattr.asp) function gives more succinct code than the [hasattr](https://www.w3schools.com/python/ref_func_hasattr.asp) function. Please use it when appropriate.

**This diff is very low risk. Green tests indicate that you can safely Accept & Ship.**

Differential Revision: D44886687

fbshipit-source-id: f3f0265251bf8008ae927b767da5749bf6828c2c
parent 18bd89b2
......@@ -111,7 +111,7 @@ class AbnormalLossChecker(object):
all_info = {
"losses": losses,
"data": data,
"model": model.module if hasattr(model, "module") else model,
"model": getattr(model, "module", model),
"prev_loss": self.prev_loss,
"step": self.prev_index + 1,
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment