Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lookup plugins: use f-strings #9324

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

russoz
Copy link
Collaborator

@russoz russoz commented Dec 23, 2024

SUMMARY

Use f-strings instead of string interpolations or string format().

ISSUE TYPE
  • Refactoring Pull Request
COMPONENT NAME

plugins/lookup/bitwarden.py
plugins/lookup/chef_databag.py
plugins/lookup/collection_version.py
plugins/lookup/consul_kv.py
plugins/lookup/credstash.py
plugins/lookup/cyberarkpassword.py
plugins/lookup/dependent.py
plugins/lookup/dig.py
plugins/lookup/dnstxt.py
plugins/lookup/dsv.py
plugins/lookup/etcd.py
plugins/lookup/etcd3.py
plugins/lookup/filetree.py
plugins/lookup/github_app_access_token.py
plugins/lookup/hiera.py
plugins/lookup/keyring.py
plugins/lookup/lastpass.py
plugins/lookup/lmdb_kv.py
plugins/lookup/manifold.py
plugins/lookup/merge_variables.py
plugins/lookup/onepassword.py
plugins/lookup/onepassword_doc.py
plugins/lookup/passwordstore.py
plugins/lookup/random_pet.py
plugins/lookup/redis.py
plugins/lookup/revbitspss.py
plugins/lookup/shelvefile.py
plugins/lookup/tss.py

@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI lookup lookup plugin needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR plugins plugin (any type) labels Dec 23, 2024
@russoz
Copy link
Collaborator Author

russoz commented Dec 23, 2024

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

plugins/lookup/dependent.py:188:0: unidiomatic-typecheck: Type comparison using type() found. Use isinstance() instead
plugins/lookup/dependent.py:217:0: unidiomatic-typecheck: Type comparison using type() found. Use isinstance() instead

click here for bot help

@felixfontein this looks like a snafu from validate-modules to me. There is no type comparison happening in those lines. Should I just add an ignore file for the file or do you want to adjust something in the validation?

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI and removed ci_verified Push fixes to PR branch to re-run CI labels Dec 23, 2024
@felixfontein felixfontein added backport-10 Automatically create a backport for the stable-10 branch check-before-release PR will be looked at again shortly before release and merged if possible. labels Dec 23, 2024
@felixfontein
Copy link
Collaborator

@felixfontein this looks like a snafu from validate-modules to me. There is no type comparison happening in those lines. Should I just add an ignore file for the file or do you want to adjust something in the validation?

For now it's best to add ignore.txt entries. The check has been removed from ansible-core 2.17 anyway, so fixing it is no longer possible.

@felixfontein
Copy link
Collaborator

(Ref: ansible/ansible@9dd3eaf)

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI and removed ci_verified Push fixes to PR branch to re-run CI labels Dec 23, 2024
@ansibullbot ansibullbot added tests tests and removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Dec 23, 2024
@@ -144,7 +144,7 @@ def __evaluate(self, expression, templar, variables):
``variables`` are the variables to use.
"""
templar.available_variables = variables or {}
expression = "{0}{1}{2}".format("{{", expression, "}}")
expression = '{{%s}}' % expression
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again the opening and ending sequence is part of the formatting string, which was intentionally not the case before. How about reverting to the original code?

Suggested change
expression = '{{%s}}' % expression
expression = "{0}{1}{2}".format("{{", expression, "}}")

Using format() is still totally legal and fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-10 Automatically create a backport for the stable-10 branch check-before-release PR will be looked at again shortly before release and merged if possible. lookup lookup plugin plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants