Fix Python 3.12 compatibility

Handle a change in Python 3.12 [1].

[1] cffb4c78d3

Change-Id: I772579d297ef51c57019218a4ca8a566987b9b5c
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-08-27 10:29:51 +01:00
parent 43e6dbaf67
commit d27282b5c7

View File

@ -232,8 +232,11 @@ class NovaClientArgumentParser(argparse.ArgumentParser):
option_tuples = (super(NovaClientArgumentParser, self)
._get_option_tuples(option_string))
if len(option_tuples) > 1:
normalizeds = [option.replace('_', '-')
for action, option, value in option_tuples]
# In Python < 3.12, this is a 3-part tuple:
# action, option_string, explicit_arg
# In Python >= 3.12, this is a 4 part tuple:
# action, option_string, sep, explicit_arg
normalizeds = [opt[1].replace('_', '-') for opt in option_tuples]
if len(set(normalizeds)) == 1:
return option_tuples[:1]
return option_tuples