Skip to content

Commit 9de592e

Browse files
committed
typing: Resolve incompatible operand issues
Change-Id: I7f3dd908053b9ace5206d0a1bd3b8258fd0264ef Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent e28046c commit 9de592e

12 files changed

Lines changed: 55 additions & 33 deletions

File tree

openstackclient/identity/v3/limit.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def take_action(self, parsed_args):
7777
)
7878
region = None
7979
if parsed_args.region:
80-
val = getattr(parsed_args, 'region', None)
81-
if 'None' not in val:
80+
if 'None' not in parsed_args.region:
8281
# NOTE (vishakha): Due to bug #1799153 and for any another
8382
# related case where GET resource API does not support the
8483
# filter by name, osc_lib.utils.find_resource() method cannot
@@ -149,11 +148,7 @@ def take_action(self, parsed_args):
149148
)
150149
region = None
151150
if parsed_args.region:
152-
region = utils.find_resource(
153-
identity_client.regions, parsed_args.region
154-
)
155-
val = getattr(parsed_args, 'region', None)
156-
if 'None' not in val:
151+
if 'None' not in parsed_args.region:
157152
# NOTE (vishakha): Due to bug #1799153 and for any another
158153
# related case where GET resource API does not support the
159154
# filter by name, osc_lib.utils.find_resource() method cannot

openstackclient/identity/v3/registered_limit.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def take_action(self, parsed_args):
6868
)
6969
region = None
7070
if parsed_args.region:
71-
val = getattr(parsed_args, 'region', None)
72-
if 'None' not in val:
71+
if 'None' not in parsed_args.region:
7372
# NOTE (vishakha): Due to bug #1799153 and for any another
7473
# related case where GET resource API does not support the
7574
# filter by name, osc_lib.utils.find_resource() method cannot
@@ -175,8 +174,7 @@ def take_action(self, parsed_args):
175174
)
176175
region = None
177176
if parsed_args.region:
178-
val = getattr(parsed_args, 'region', None)
179-
if 'None' not in val:
177+
if 'None' not in parsed_args.region:
180178
# NOTE (vishakha): Due to bug #1799153 and for any another
181179
# related case where GET resource API does not support the
182180
# filter by name, osc_lib.utils.find_resource() method cannot
@@ -280,8 +278,7 @@ def take_action(self, parsed_args):
280278

281279
region = None
282280
if parsed_args.region:
283-
val = getattr(parsed_args, 'region', None)
284-
if 'None' not in val:
281+
if 'None' not in parsed_args.region:
285282
# NOTE (vishakha): Due to bug #1799153 and for any another
286283
# related case where GET resource API does not support the
287284
# filter by name, osc_lib.utils.find_resource() method cannot

openstackclient/network/v2/port.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import copy
1818
import json
1919
import logging
20+
import typing as ty
2021

2122
from cliff import columns as cliff_columns
2223
from osc_lib.cli import format_columns
@@ -39,6 +40,8 @@ def human_readable(self):
3940

4041

4142
class SubPortColumn(format_columns.ListDictColumn):
43+
_value: ty.Any
44+
4245
def _retrieve_subports(self):
4346
if isinstance(self._value, dict):
4447
self._value = self._value['sub_ports']

openstackclient/tests/functional/common/test_quota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QuotaTests(base.TestCase):
2525
test runs as these may run in parallel and otherwise step on each other.
2626
"""
2727

28-
PROJECT_NAME = None
28+
PROJECT_NAME: str
2929

3030
@classmethod
3131
def setUpClass(cls):

openstackclient/tests/functional/compute/v2/common.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
class ComputeTestCase(base.TestCase):
2323
"""Common functional test bits for Compute commands"""
2424

25-
flavor_name = None
26-
image_name = None
27-
network_arg = None
25+
flavor_name: str
26+
image_name: str
27+
network_arg: str
2828

2929
def setUp(self):
3030
"""Select common resources"""
@@ -34,7 +34,7 @@ def setUp(self):
3434
self.network_arg = self.get_network()
3535

3636
@classmethod
37-
def get_flavor(cls):
37+
def get_flavor(cls) -> str:
3838
# NOTE(rtheis): Get cirros256 or m1.tiny flavors since functional
3939
# tests may create other flavors.
4040
flavors = cls.openstack("flavor list", parse_output=True)
@@ -43,10 +43,13 @@ def get_flavor(cls):
4343
if flavor['Name'] in ['m1.tiny', 'cirros256']:
4444
server_flavor = flavor['Name']
4545
break
46+
47+
assert server_flavor is not None
48+
4649
return server_flavor
4750

4851
@classmethod
49-
def get_image(cls):
52+
def get_image(cls) -> str:
5053
# NOTE(rtheis): Get first Cirros image since functional tests may
5154
# create other images. Image may be named '-uec' or
5255
# '-disk'.
@@ -59,10 +62,13 @@ def get_image(cls):
5962
):
6063
server_image = image['Name']
6164
break
65+
66+
assert server_image is not None
67+
6268
return server_image
6369

6470
@classmethod
65-
def get_network(cls):
71+
def get_network(cls) -> str:
6672
try:
6773
# NOTE(rtheis): Get private network since functional tests may
6874
# create other networks.

openstackclient/tests/functional/network/v2/test_address_group.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def test_address_group_list(self):
7575
self.assertNotEqual(admin_project_id, demo_project_id)
7676
self.assertEqual(admin_project_id, auth_project_id)
7777

78+
# type narrow
79+
assert admin_project_id is not None
80+
assert demo_project_id is not None
81+
7882
name1 = uuid.uuid4().hex
7983
cmd_output = self.openstack(
8084
'address group create ' + name1,

openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ def test_l3_conntrack_helper_list(self):
9494
self.assertIn(ct, expected_helpers)
9595

9696
def test_l3_conntrack_helper_set_and_show(self):
97-
helper = {'helper': 'tftp', 'protocol': 'udp', 'port': 69}
97+
helper = 'tftp'
98+
proto = 'udp'
99+
port = 69
98100
router_id = self._create_router()
99-
created_helper = self._create_helpers(router_id, [helper])[0]
101+
created_helper = self._create_helpers(
102+
router_id,
103+
[{'helper': helper, 'protocol': proto, 'port': port}],
104+
)[0]
100105
output = self.openstack(
101106
'network l3 conntrack helper show {router_id} {ct_id} '
102107
'-f json'.format(
@@ -105,16 +110,16 @@ def test_l3_conntrack_helper_set_and_show(self):
105110
),
106111
parse_output=True,
107112
)
108-
self.assertEqual(helper['helper'], output['helper'])
109-
self.assertEqual(helper['protocol'], output['protocol'])
110-
self.assertEqual(helper['port'], output['port'])
113+
self.assertEqual(port, output['port'])
114+
self.assertEqual(helper, output['helper'])
115+
self.assertEqual(proto, output['protocol'])
111116

112117
raw_output = self.openstack(
113118
'network l3 conntrack helper set {router_id} {ct_id} '
114119
'--port {port} '.format(
115120
router_id=router_id,
116121
ct_id=created_helper['id'],
117-
port=helper['port'] + 1,
122+
port=port + 1,
118123
)
119124
)
120125
self.assertOutput('', raw_output)
@@ -127,6 +132,6 @@ def test_l3_conntrack_helper_set_and_show(self):
127132
),
128133
parse_output=True,
129134
)
130-
self.assertEqual(helper['port'] + 1, output['port'])
131-
self.assertEqual(helper['helper'], output['helper'])
132-
self.assertEqual(helper['protocol'], output['protocol'])
135+
self.assertEqual(port + 1, output['port'])
136+
self.assertEqual(helper, output['helper'])
137+
self.assertEqual(proto, output['protocol'])

openstackclient/tests/functional/network/v2/test_local_ip.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def test_local_ip_list(self):
7777
self.assertNotEqual(admin_project_id, demo_project_id)
7878
self.assertEqual(admin_project_id, auth_project_id)
7979

80+
# type narrow
81+
assert admin_project_id is not None
82+
assert demo_project_id is not None
83+
8084
name1 = uuid.uuid4().hex
8185
cmd_output = self.openstack(
8286
'local ip create ' + name1,

openstackclient/tests/functional/network/v2/test_network_meter_rule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
class TestMeterRule(common.NetworkTests):
2323
"""Functional tests for meter rule"""
2424

25-
METER_ID = None
26-
METER_RULE_ID = None
25+
METER_ID: str
26+
METER_RULE_ID: str
2727

2828
@classmethod
2929
def setUpClass(cls):

openstackclient/tests/functional/network/v2/test_network_rbac.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
class NetworkRBACTests(common.NetworkTests):
1919
"""Functional tests for network rbac"""
2020

21-
OBJECT_ID = None
22-
ID = None
21+
OBJECT_ID: str
22+
ID: str
2323
HEADERS = ['ID']
2424
FIELDS = ['id']
2525

0 commit comments

Comments
 (0)