Remove locals() from code base and enable H501 pep/flake rule

Change-Id: I104c70e053525e8c462e5bdbca733609303ee13b
Related-Bug: #1333290