[codemod] Replace hasattr with getattr in caffe2/test/distributed/fsdp/test_fsdp_optim_state.py (#100360)
Summary:
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.**
Test Plan: Sandcastle
Differential Revision: D44886500
Pull Request resolved: https://github.com/pytorch/pytorch/pull/100360
Approved by: https://github.com/rohan-varma, https://github.com/Skylion007, https://github.com/awgu