Skip to content

Commit 28bd00a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "typing: Correct type for missing attributes"
2 parents e6ae7d8 + e28046c commit 28bd00a

File tree

12 files changed

+36
-29
lines changed

12 files changed

+36
-29
lines changed

openstackclient/common/project_cleanup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def ask_user_yesno(msg):
3636
:return bool: User choice
3737
"""
3838
while True:
39-
answer = getpass._raw_input('{} [{}]: '.format(msg, 'y/n'))
39+
answer = getpass.getpass('{} [{}]: '.format(msg, 'y/n'))
4040
if answer in ('y', 'Y', 'yes'):
4141
return True
4242
elif answer in ('n', 'N', 'no'):

openstackclient/common/quota.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import itertools
1919
import logging
2020
import sys
21+
import typing as ty
2122

2223
from openstack import exceptions as sdk_exceptions
2324
from osc_lib.command import command
@@ -199,7 +200,7 @@ def _network_quota_to_dict(network_quota, detail=False):
199200
#
200201
# so we need to make conversion to have data in same format from
201202
# all of the services
202-
result = {"usage": {}, "reservation": {}}
203+
result: dict[str, ty.Any] = {"usage": {}, "reservation": {}}
203204
for key, values in dict_quota.items():
204205
if values is None:
205206
continue

openstackclient/compute/v2/keypair.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def take_action(self, parsed_args):
126126
kwargs = {'name': parsed_args.name}
127127

128128
if parsed_args.public_key:
129-
generated_keypair = None
130129
try:
131130
with open(os.path.expanduser(parsed_args.public_key)) as p:
132131
public_key = p.read()

openstackclient/compute/v2/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,7 @@ def _match_image(image_api, wanted_properties):
19701970

19711971
# convert from the novaclient-derived "NIC" view to the actual
19721972
# "network" view
1973-
network = {}
1973+
network: dict[str, str] = {}
19741974

19751975
if nic['net-id']:
19761976
network['uuid'] = nic['net-id']
@@ -1986,7 +1986,7 @@ def _match_image(image_api, wanted_properties):
19861986
if nic.get('tag'): # tags are optional
19871987
network['tag'] = nic['tag']
19881988

1989-
networks.append(network)
1989+
networks.append(network) # type: ignore[union-attr]
19901990

19911991
if not parsed_args.nics and sdk_utils.supports_microversion(
19921992
compute_client, '2.37'

openstackclient/identity/v2_0/user.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,7 @@ def take_action(self, parsed_args):
249249
data = identity_client.users.list(tenant_id=project)
250250

251251
if parsed_args.project:
252-
d = {}
253-
for s in data:
254-
d[s.id] = s
255-
data = d.values()
252+
data = {s.id: s for s in data}.values()
256253

257254
if parsed_args.long:
258255
# FIXME(dtroyer): Sometimes user objects have 'tenant_id' instead

openstackclient/identity/v3/user.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import copy
1919
import logging
20+
import typing as ty
2021

2122
from openstack import exceptions as sdk_exc
2223
from osc_lib.command import command
@@ -58,7 +59,7 @@ def _format_user(user):
5859

5960

6061
def _get_options_for_user(identity_client, parsed_args):
61-
options = {}
62+
options: dict[str, ty.Any] = {}
6263
if parsed_args.ignore_lockout_failure_attempts:
6364
options['ignore_lockout_failure_attempts'] = True
6465
if parsed_args.no_ignore_lockout_failure_attempts:

openstackclient/image/v2/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def _take_action_image(self, parsed_args):
428428

429429
# Build an attribute dict from the parsed args, only include
430430
# attributes that were actually set on the command line
431-
kwargs = {'allow_duplicates': True}
431+
kwargs: dict[str, ty.Any] = {'allow_duplicates': True}
432432
copy_attrs = (
433433
'name',
434434
'id',
@@ -611,7 +611,7 @@ def _take_action_volume(self, parsed_args):
611611
volume_client.volumes,
612612
parsed_args.volume,
613613
)
614-
kwargs = {
614+
kwargs: dict[str, ty.Any] = {
615615
'visibility': None,
616616
'protected': None,
617617
}
@@ -1575,7 +1575,7 @@ def take_action(self, parsed_args):
15751575
else:
15761576
fp = get_data_from_stdin()
15771577

1578-
kwargs = {}
1578+
kwargs: dict[str, ty.Any] = {}
15791579

15801580
if parsed_args.progress and parsed_args.filename:
15811581
# NOTE(stephenfin): we only show a progress bar if the user

openstackclient/network/common.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
#
1313

1414
import abc
15+
import argparse
1516
import contextlib
1617
import logging
1718
import typing as ty
1819

20+
import cliff.app
1921
import openstack.exceptions
2022
from osc_lib.cli import parseractions
2123
from osc_lib.command import command
@@ -66,6 +68,8 @@ class NetDetectionMixin(metaclass=abc.ABCMeta):
6668
present the options for both network types, often qualified accordingly.
6769
"""
6870

71+
app: cliff.app.App
72+
6973
@property
7074
def _network_type(self):
7175
"""Discover whether the running cloud is using neutron or nova-network.
@@ -132,9 +136,9 @@ def split_help(network_help, compute_help):
132136
)
133137
)
134138

135-
def get_parser(self, prog_name):
139+
def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
136140
LOG.debug('get_parser(%s)', prog_name)
137-
parser = super().get_parser(prog_name)
141+
parser = super().get_parser(prog_name) # type: ignore
138142
parser = self.update_parser_common(parser)
139143
LOG.debug('common parser: %s', parser)
140144
if self.is_neutron or self.is_docs_build:

openstackclient/network/v2/network_meter_rule.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Meter Rule Implementations"""
1515

1616
import logging
17+
import typing as ty
1718

1819
from osc_lib.command import command
1920
from osc_lib import exceptions
@@ -34,7 +35,7 @@ def _get_columns(item):
3435

3536

3637
def _get_attrs(client_manager, parsed_args):
37-
attrs = {}
38+
attrs: dict[str, ty.Any] = {}
3839

3940
if parsed_args.exclude:
4041
attrs['excluded'] = True

openstackclient/network/v2/router.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import copy
1919
import json
2020
import logging
21+
import typing as ty
2122

2223
from cliff import columns as cliff_columns
2324
from osc_lib.cli import format_columns
@@ -104,21 +105,21 @@ def _passed_multiple_gateways(extension_supported, external_gateways):
104105

105106

106107
def _get_external_gateway_attrs(client_manager, parsed_args):
107-
attrs = {}
108+
attrs: dict[str, ty.Any] = {}
108109

109110
if parsed_args.external_gateways:
110111
external_gateways: collections.defaultdict[str, list[dict]] = (
111112
collections.defaultdict(list)
112113
)
113114
n_client = client_manager.network
114-
first_network_id = None
115+
first_network_id = ''
115116

116117
for gw_net_name_or_id in parsed_args.external_gateways:
117118
gateway_info = {}
118119
gw_net = n_client.find_network(
119120
gw_net_name_or_id, ignore_missing=False
120121
)
121-
if first_network_id is None:
122+
if not first_network_id:
122123
first_network_id = gw_net.id
123124
gateway_info['network_id'] = gw_net.id
124125
if 'disable_snat' in parsed_args and parsed_args.disable_snat:
@@ -146,7 +147,7 @@ def _get_external_gateway_attrs(client_manager, parsed_args):
146147
for ip_spec in parsed_args.fixed_ips:
147148
# If there is only one gateway, this value will represent the
148149
# network ID for it, otherwise it will be overridden.
149-
ip_net_id = first_network_id
150+
ip_net_id: str = first_network_id
150151

151152
if ip_spec.get('subnet', False):
152153
subnet_name_id = ip_spec.pop('subnet')

0 commit comments

Comments
 (0)