mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 12:51:25 -07:00
[PR #9324/6cd3f79e backport][stable-10] lookup plugins: use f-strings (#9367)
lookup plugins: use f-strings (#9324)
* lookup plugins: use f-strings
* add changelog frag
* manual change for few occurrences
* Update plugins/lookup/dependent.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* adjustment from review
* no f-string for you
* Update plugins/lookup/dependent.py
Co-authored-by: Felix Fontein <felix@fontein.de>
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 6cd3f79e19
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
74bd7f1471
commit
a5c448d6e8
31 changed files with 165 additions and 149 deletions
|
@ -173,8 +173,7 @@ class LookupModule(LookupBase):
|
|||
values = self.__evaluate(expression, templar, variables=vars)
|
||||
except Exception as e:
|
||||
raise AnsibleLookupError(
|
||||
'Caught "{error}" while evaluating {key!r} with item == {item!r}'.format(
|
||||
error=e, key=key, item=current))
|
||||
f'Caught "{e}" while evaluating {key!r} with item == {current!r}')
|
||||
|
||||
if isinstance(values, Mapping):
|
||||
for idx, val in sorted(values.items()):
|
||||
|
@ -186,8 +185,7 @@ class LookupModule(LookupBase):
|
|||
self.__process(result, terms, index + 1, current, templar, variables)
|
||||
else:
|
||||
raise AnsibleLookupError(
|
||||
'Did not obtain dictionary or list while evaluating {key!r} with item == {item!r}, but {type}'.format(
|
||||
key=key, item=current, type=type(values)))
|
||||
f'Did not obtain dictionary or list while evaluating {key!r} with item == {current!r}, but {type(values)}')
|
||||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
"""Generate list."""
|
||||
|
@ -201,16 +199,14 @@ class LookupModule(LookupBase):
|
|||
for index, term in enumerate(terms):
|
||||
if not isinstance(term, Mapping):
|
||||
raise AnsibleLookupError(
|
||||
'Parameter {index} must be a dictionary, got {type}'.format(
|
||||
index=index, type=type(term)))
|
||||
f'Parameter {index} must be a dictionary, got {type(term)}')
|
||||
if len(term) != 1:
|
||||
raise AnsibleLookupError(
|
||||
'Parameter {index} must be a one-element dictionary, got {count} elements'.format(
|
||||
index=index, count=len(term)))
|
||||
f'Parameter {index} must be a one-element dictionary, got {len(term)} elements')
|
||||
k, v = list(term.items())[0]
|
||||
if k in vars_so_far:
|
||||
raise AnsibleLookupError(
|
||||
'The variable {key!r} appears more than once'.format(key=k))
|
||||
f'The variable {k!r} appears more than once')
|
||||
vars_so_far.add(k)
|
||||
if isinstance(v, string_types):
|
||||
data.append((k, v, None))
|
||||
|
@ -218,7 +214,6 @@ class LookupModule(LookupBase):
|
|||
data.append((k, None, v))
|
||||
else:
|
||||
raise AnsibleLookupError(
|
||||
'Parameter {key!r} (index {index}) must have a value of type string, dictionary or list, got type {type}'.format(
|
||||
index=index, key=k, type=type(v)))
|
||||
f'Parameter {k!r} (index {index}) must have a value of type string, dictionary or list, got type {type(v)}')
|
||||
self.__process(result, data, 0, {}, templar, variables)
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue