Skip to content

Commit 87df896

Browse files
committed
trivial: Enable ruff-specific (RUF) rules
Change-Id: I60cc0c22c692414f758df431c049e51b1baecfc7 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 64cf0c3 commit 87df896

46 files changed

Lines changed: 145 additions & 140 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openstackclient/api/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def find_bulk(self, path, **kwargs):
254254
items = self.list(path)
255255
if isinstance(items, dict):
256256
# strip off the enclosing dict
257-
key = list(items.keys())[0]
257+
key = next(iter(items.keys()))
258258
items = items[key]
259259

260260
ret = []

openstackclient/common/progressbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _display_progress_bar(self, size_read):
4040
# Output something like this: [==========> ] 49%
4141
sys.stdout.write(
4242
'\r[{:<30}] {:.0%}'.format(
43-
'=' * int(round(self._percent * 29)) + '>', self._percent
43+
'=' * round(self._percent * 29) + '>', self._percent
4444
)
4545
)
4646
sys.stdout.flush()

openstackclient/common/quota.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,13 +827,11 @@ def _normalize_names(section: dict) -> None:
827827
_normalize_names(info["usage"])
828828

829829
# Remove the 'id' field since it's not very useful
830-
if 'id' in info:
831-
del info['id']
830+
info.pop('id', None)
832831

833832
# Remove the sdk-derived fields
834833
for field in ('location', 'name', 'force'):
835-
if field in info:
836-
del info[field]
834+
info.pop(field, None)
837835

838836
if not parsed_args.usage:
839837
result = [{'resource': k, 'limit': v} for k, v in info.items()]

openstackclient/compute/v2/server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,9 @@ def __call__(self, parser, namespace, values, option_string=None):
940940
}
941941

942942
for kv_str in values.split(','):
943-
k, sep, v = kv_str.partition('=')
943+
k, _sep, v = kv_str.partition('=')
944944

945-
if k not in list(info) + ['tag'] or not v:
945+
if k not in [*list(info), 'tag'] or not v:
946946
msg = _(
947947
"Invalid argument %s; argument must be of form "
948948
"'net-id=net-uuid,port-id=port-uuid,v4-fixed-ip=ip-addr,"
@@ -975,7 +975,7 @@ def __call__(self, parser, namespace, values, option_string=None):
975975
if getattr(namespace, self.dest, None) is None:
976976
setattr(namespace, self.dest, [])
977977

978-
dev_name, sep, dev_map = values.partition('=')
978+
dev_name, _sep, dev_map = values.partition('=')
979979
dev_map = dev_map.split(':') if dev_map else dev_map
980980
if not dev_name or not dev_map or len(dev_map) > 4:
981981
msg = _(
@@ -5017,7 +5017,7 @@ def take_action(self, parsed_args):
50175017
ip_address_family,
50185018
)
50195019

5020-
cmd = ' '.join(['ssh', ip_address] + args)
5020+
cmd = ' '.join(['ssh', ip_address, *args])
50215021
LOG.debug('ssh command: %s', cmd)
50225022
# we intentionally pass through user-provided arguments and run this in
50235023
# the user's shell

openstackclient/identity/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _get_token_resource(client, resource, parsed_name, parsed_domain=None):
180180
return parsed_name
181181
return obj['id'] if obj['name'] == parsed_name else parsed_name
182182
# diaper defense in case parsing the token fails
183-
except Exception: # noqa
183+
except Exception:
184184
return parsed_name
185185

186186

openstackclient/identity/v2_0/role_assignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from osc_lib import utils
1818

1919
from openstackclient import command
20-
from openstackclient.i18n import _ # noqa
20+
from openstackclient.i18n import _
2121

2222

2323
class ListRoleAssignment(command.Lister):

openstackclient/identity/v3/identity_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ def get_parser(self, prog_name):
188188
parser.add_argument(
189189
'--id',
190190
metavar='<id>',
191-
help=_('The Identity Providers’ ID attribute'),
191+
help=_('Filter identity providers by ID'),
192192
)
193193
parser.add_argument(
194194
'--enabled',
195195
dest='enabled',
196196
action='store_true',
197-
help=_('The Identity Providers that are enabled will be returned'),
197+
help=_('List only enabled identity providers'),
198198
)
199199
return parser
200200

openstackclient/identity/v3/role.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ def take_action(self, parsed_args):
416416
return (
417417
('ID', 'Name', 'Domain'),
418418
(
419-
utils.get_item_properties(s, ('id', 'name'))
420-
+ (domain.name,)
419+
(
420+
*utils.get_item_properties(s, ('id', 'name')),
421+
domain.name,
422+
)
421423
for s in data
422424
),
423425
)

openstackclient/image/v1/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def take_action(self, parsed_args):
299299
volume_client.volumes,
300300
parsed_args.volume,
301301
)
302-
response, body = volume_client.volumes.upload_to_image(
302+
_response, body = volume_client.volumes.upload_to_image(
303303
source_volume.id,
304304
parsed_args.force,
305305
parsed_args.name,
@@ -498,7 +498,7 @@ def take_action(self, parsed_args):
498498

499499
if parsed_args.property:
500500
# NOTE(dtroyer): coerce to a list to subscript it in py3
501-
attr, value = list(parsed_args.property.items())[0]
501+
attr, value = next(iter(parsed_args.property.items()))
502502
api_utils.simple_filter(
503503
images,
504504
attr=attr,

openstackclient/network/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def str2dict(strdict: str) -> dict[str, str]:
7878
else:
7979
kvlist[i - 1] = f"{kvlist[i - 1]};{kv}"
8080
for kv in kvlist:
81-
key, sep, value = kv.partition(':')
81+
key, value = kv.split(':', 1)
8282
result[key] = value
8383
return result
8484

@@ -173,11 +173,15 @@ def is_ipv6_protocol(protocol):
173173
# However, while the OSC CLI doesn't document the protocol,
174174
# the code must still handle it. In addition, handle both
175175
# protocol names and numbers.
176-
if (
177-
protocol is not None
178-
and protocol.startswith('ipv6-')
179-
or protocol in ['icmpv6', '41', '43', '44', '58', '59', '60']
180-
):
176+
if (protocol is not None and protocol.startswith('ipv6-')) or protocol in [
177+
'icmpv6',
178+
'41',
179+
'43',
180+
'44',
181+
'58',
182+
'59',
183+
'60',
184+
]:
181185
return True
182186
else:
183187
return False

0 commit comments

Comments
 (0)