plugins: replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting (#9379)

* Replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting.

* Improve formulation.

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

* Use more f-strings.

* Remove unicode prefix for strings.

---------

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
Felix Fontein 2024-12-28 22:47:18 +01:00 committed by GitHub
commit 2203560867
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 111 additions and 99 deletions

View file

@ -211,7 +211,7 @@ class InventoryModule(BaseInventoryPlugin):
with open(path, 'r') as json_file:
return json.load(json_file)
except (IOError, json.decoder.JSONDecodeError) as err:
raise AnsibleParserError(f'Could not load the test data from {to_native(path)}: {to_native(err)}')
raise AnsibleParserError(f'Could not load the test data from {to_native(path)}: {err}')
def save_json_data(self, path, file_name=None):
"""save data as json
@ -241,7 +241,7 @@ class InventoryModule(BaseInventoryPlugin):
with open(os.path.abspath(os.path.join(cwd, *path)), 'w') as json_file:
json.dump(self.data, json_file)
except IOError as err:
raise AnsibleParserError(f'Could not save data: {to_native(err)}')
raise AnsibleParserError(f'Could not save data: {err}')
def verify_file(self, path):
"""Check the config
@ -281,7 +281,7 @@ class InventoryModule(BaseInventoryPlugin):
if not isinstance(url, str):
return False
if not url.startswith(('unix:', 'https:')):
raise AnsibleError(f'URL is malformed: {to_native(url)}')
raise AnsibleError(f'URL is malformed: {url}')
return True
def _connect_to_socket(self):
@ -306,7 +306,7 @@ class InventoryModule(BaseInventoryPlugin):
return socket_connection
except LXDClientException as err:
error_storage[url] = err
raise AnsibleError(f'No connection to the socket: {to_native(error_storage)}')
raise AnsibleError(f'No connection to the socket: {error_storage}')
def _get_networks(self):
"""Get Networknames
@ -579,7 +579,7 @@ class InventoryModule(BaseInventoryPlugin):
else:
path[instance_name][key] = value
except KeyError as err:
raise AnsibleParserError(f"Unable to store Information: {to_native(err)}")
raise AnsibleParserError(f"Unable to store Information: {err}")
def extract_information_from_instance_configs(self):
"""Process configuration information
@ -792,7 +792,7 @@ class InventoryModule(BaseInventoryPlugin):
network = ipaddress.ip_network(to_text(self.groupby[group_name].get('attribute')))
except ValueError as err:
raise AnsibleParserError(
f"Error while parsing network range {self.groupby[group_name].get('attribute')}: {to_native(err)}")
f"Error while parsing network range {self.groupby[group_name].get('attribute')}: {err}")
for instance_name in self.inventory.hosts:
if self.data['inventory'][instance_name].get('network_interfaces') is not None:
@ -1120,6 +1120,6 @@ class InventoryModule(BaseInventoryPlugin):
self.url = self.get_option('url')
except Exception as err:
raise AnsibleParserError(
f'All correct options required: {to_native(err)}')
f'All correct options required: {err}')
# Call our internal helper to populate the dynamic inventory
self._populate()