diff options
author | Matt Clay <mclay@redhat.com> | 2021-08-12 15:07:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-12 15:07:06 -0700 |
commit | 99a79e1969472ab4ba5c0bd0cab61927b9aa93d9 (patch) | |
tree | eff0efdf8d721c836a4081191039d2dfcfde68fd /test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py | |
parent | 394860560a553e85e1934699bbab1ba615922c85 (diff) | |
download | ansible-99a79e1969472ab4ba5c0bd0cab61927b9aa93d9.tar.gz |
ansible-test - Move code from _data to _util. (#75495)
* Update paths to match relocated files.
* Update ansible-test symlink paths.
* Update path classification.
* Update MANIFEST.in
* Update sanity test context paths.
* Update sanity ignores.
* Update shebang sanity test.
* Update configure-remoting-ps1 sanity test.
* Update BOTMETA.yml to reflect new paths.
* Update paths in collection loader comments.
* Update Makefile for ansible-test.
* Update docs.
* Add changelog fragment.
Diffstat (limited to 'test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py')
-rwxr-xr-x | test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py new file mode 100755 index 0000000000..237ee5b1c1 --- /dev/null +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import re +import sys + + +def main(): + for path in sys.argv[1:] or sys.stdin.read().splitlines(): + with open(path, 'r') as path_fd: + for line, text in enumerate(path_fd.readlines()): + match = re.search(r'\.(iterkeys)', text) + + if match: + print('%s:%d:%d: use `dict.keys` or `for key in dict:` instead of `dict.iterkeys`' % ( + path, line + 1, match.start(1) + 1)) + + +if __name__ == '__main__': + main() |