osc-lib 3.1.0__py3-none-any.whl → 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. osc_lib/api/api.py +67 -30
  2. osc_lib/api/auth.py +39 -25
  3. osc_lib/api/utils.py +10 -5
  4. osc_lib/cli/client_config.py +55 -35
  5. osc_lib/cli/format_columns.py +19 -17
  6. osc_lib/cli/identity.py +14 -3
  7. osc_lib/cli/pagination.py +83 -0
  8. osc_lib/cli/parseractions.py +116 -37
  9. osc_lib/clientmanager.py +49 -28
  10. osc_lib/command/command.py +20 -9
  11. osc_lib/command/timing.py +11 -1
  12. osc_lib/exceptions.py +13 -3
  13. osc_lib/logs.py +19 -9
  14. osc_lib/py.typed +0 -0
  15. osc_lib/shell.py +73 -56
  16. osc_lib/tests/api/fakes.py +1 -1
  17. osc_lib/tests/api/test_api.py +5 -5
  18. osc_lib/tests/api/test_utils.py +1 -1
  19. osc_lib/tests/cli/test_client_config.py +1 -1
  20. osc_lib/tests/cli/test_format_columns.py +1 -1
  21. osc_lib/tests/cli/test_parseractions.py +48 -100
  22. osc_lib/tests/command/test_timing.py +2 -2
  23. osc_lib/tests/fakes.py +10 -10
  24. osc_lib/tests/test_clientmanager.py +1 -1
  25. osc_lib/tests/test_logs.py +2 -2
  26. osc_lib/tests/test_shell.py +10 -10
  27. osc_lib/tests/utils/__init__.py +6 -25
  28. osc_lib/tests/utils/test_tags.py +22 -7
  29. osc_lib/tests/utils/test_utils.py +4 -14
  30. osc_lib/utils/__init__.py +183 -111
  31. osc_lib/utils/columns.py +25 -11
  32. osc_lib/utils/tags.py +39 -21
  33. {osc_lib-3.1.0.dist-info → osc_lib-4.0.0.dist-info}/AUTHORS +1 -0
  34. {osc_lib-3.1.0.dist-info → osc_lib-4.0.0.dist-info}/METADATA +11 -13
  35. osc_lib-4.0.0.dist-info/RECORD +53 -0
  36. {osc_lib-3.1.0.dist-info → osc_lib-4.0.0.dist-info}/WHEEL +1 -1
  37. osc_lib-4.0.0.dist-info/pbr.json +1 -0
  38. osc_lib-3.1.0.dist-info/RECORD +0 -51
  39. osc_lib-3.1.0.dist-info/pbr.json +0 -1
  40. {osc_lib-3.1.0.dist-info → osc_lib-4.0.0.dist-info}/LICENSE +0 -0
  41. {osc_lib-3.1.0.dist-info → osc_lib-4.0.0.dist-info}/top_level.txt +0 -0
osc_lib/api/api.py CHANGED
@@ -12,6 +12,11 @@
12
12
  #
13
13
 
14
14
  """Base API Library"""
15
+
16
+ import builtins
17
+ import typing as ty
18
+ import warnings
19
+
15
20
  from keystoneauth1 import exceptions as ksa_exceptions
16
21
  from keystoneauth1 import session as ksa_session
17
22
  import requests
@@ -20,7 +25,7 @@ from osc_lib import exceptions
20
25
  from osc_lib.i18n import _
21
26
 
22
27
 
23
- class BaseAPI(object):
28
+ class BaseAPI:
24
29
  """Base API wrapper for keystoneauth1.session.Session
25
30
 
26
31
  Encapsulate the translation between keystoneauth1.session.Session
@@ -41,8 +46,12 @@ class BaseAPI(object):
41
46
  HEADER_NAME = "OpenStack-API-Version"
42
47
 
43
48
  def __init__(
44
- self, session=None, service_type=None, endpoint=None, **kwargs
45
- ):
49
+ self,
50
+ session: ty.Optional[ksa_session.Session] = None,
51
+ service_type: ty.Optional[str] = None,
52
+ endpoint: ty.Optional[str] = None,
53
+ **kwargs: ty.Any,
54
+ ) -> None:
46
55
  """Base object that contains some common API objects and methods
47
56
 
48
57
  :param keystoneauth1.session.Session session:
@@ -57,7 +66,13 @@ class BaseAPI(object):
57
66
  Keyword arguments passed to keystoneauth1.session.Session().
58
67
  """
59
68
 
60
- super(BaseAPI, self).__init__()
69
+ warnings.warn(
70
+ 'The BaseAPI class is deprecated for removal. Consider using '
71
+ 'openstacksdk instead else vendoring this code into your client',
72
+ category=DeprecationWarning,
73
+ )
74
+
75
+ super().__init__()
61
76
 
62
77
  # Create a keystoneauth1.session.Session if one is not supplied
63
78
  if not session:
@@ -68,7 +83,7 @@ class BaseAPI(object):
68
83
  self.service_type = service_type
69
84
  self.endpoint = self._munge_endpoint(endpoint)
70
85
 
71
- def _munge_endpoint(self, endpoint):
86
+ def _munge_endpoint(self, endpoint: ty.Optional[str]) -> ty.Optional[str]:
72
87
  """Hook to allow subclasses to massage the passed-in endpoint
73
88
 
74
89
  Hook to massage passed-in endpoints from arbitrary sources,
@@ -89,7 +104,13 @@ class BaseAPI(object):
89
104
  else:
90
105
  return endpoint
91
106
 
92
- def _request(self, method, url, session=None, **kwargs):
107
+ def _request(
108
+ self,
109
+ method: str,
110
+ url: str,
111
+ session: ty.Optional[ksa_session.Session] = None,
112
+ **kwargs: ty.Any,
113
+ ) -> requests.Response:
93
114
  """Perform call into session
94
115
 
95
116
  All API calls are funneled through this method to provide a common
@@ -135,7 +156,13 @@ class BaseAPI(object):
135
156
 
136
157
  # The basic action methods all take a Session and return dict/lists
137
158
 
138
- def create(self, url, session=None, method=None, **params):
159
+ def create(
160
+ self,
161
+ url: str,
162
+ session: ty.Optional[ksa_session.Session] = None,
163
+ method: ty.Optional[str] = None,
164
+ **params: ty.Any,
165
+ ) -> ty.Union[requests.Response, ty.Any]:
139
166
  """Create a new resource
140
167
 
141
168
  :param string url:
@@ -155,7 +182,12 @@ class BaseAPI(object):
155
182
  except requests.JSONDecodeError:
156
183
  return ret
157
184
 
158
- def delete(self, url, session=None, **params):
185
+ def delete(
186
+ self,
187
+ url: str,
188
+ session: ty.Optional[ksa_session.Session] = None,
189
+ **params: ty.Any,
190
+ ) -> requests.Response:
159
191
  """Delete a resource
160
192
 
161
193
  :param string url:
@@ -168,13 +200,13 @@ class BaseAPI(object):
168
200
 
169
201
  def list(
170
202
  self,
171
- path,
172
- session=None,
173
- body=None,
174
- detailed=False,
175
- headers=None,
176
- **params
177
- ):
203
+ path: str,
204
+ session: ty.Optional[ksa_session.Session] = None,
205
+ body: ty.Any = None,
206
+ detailed: bool = False,
207
+ headers: ty.Optional[dict[str, str]] = None,
208
+ **params: ty.Any,
209
+ ) -> ty.Union[requests.Response, ty.Any]:
178
210
  """Return a list of resources
179
211
 
180
212
  GET ${ENDPOINT}/${PATH}?${PARAMS}
@@ -225,11 +257,11 @@ class BaseAPI(object):
225
257
 
226
258
  def find_attr(
227
259
  self,
228
- path,
229
- value=None,
230
- attr=None,
231
- resource=None,
232
- ):
260
+ path: str,
261
+ value: ty.Optional[str] = None,
262
+ attr: ty.Optional[str] = None,
263
+ resource: ty.Optional[str] = None,
264
+ ) -> ty.Any:
233
265
  """Find a resource via attribute or ID
234
266
 
235
267
  Most APIs return a list wrapped by a dict with the resource
@@ -259,7 +291,7 @@ class BaseAPI(object):
259
291
  if resource is None:
260
292
  resource = path
261
293
 
262
- def getlist(kw):
294
+ def getlist(kw: dict[str, ty.Any]) -> ty.Any:
263
295
  """Do list call, unwrap resource dict if present"""
264
296
  ret = self.list(path, **kw)
265
297
  if isinstance(ret, dict) and resource in ret:
@@ -289,7 +321,12 @@ class BaseAPI(object):
289
321
  msg % {'resource': resource, 'attr': attr, 'value': value}
290
322
  )
291
323
 
292
- def find_bulk(self, path, headers=None, **kwargs):
324
+ def find_bulk(
325
+ self,
326
+ path: str,
327
+ headers: ty.Optional[dict[str, str]] = None,
328
+ **kwargs: ty.Any,
329
+ ) -> builtins.list[ty.Any]:
293
330
  """Bulk load and filter locally
294
331
 
295
332
  :param string path:
@@ -317,7 +354,7 @@ class BaseAPI(object):
317
354
 
318
355
  return ret
319
356
 
320
- def find_one(self, path, **kwargs):
357
+ def find_one(self, path: str, **kwargs: ty.Any) -> ty.Any:
321
358
  """Find a resource by name or ID
322
359
 
323
360
  :param string path:
@@ -338,11 +375,11 @@ class BaseAPI(object):
338
375
 
339
376
  def find(
340
377
  self,
341
- path,
342
- value=None,
343
- attr=None,
344
- headers=None,
345
- ):
378
+ path: str,
379
+ value: ty.Optional[str] = None,
380
+ attr: ty.Optional[str] = None,
381
+ headers: ty.Optional[dict[str, str]] = None,
382
+ ) -> ty.Any:
346
383
  """Find a single resource by name or ID
347
384
 
348
385
  :param string path:
@@ -355,14 +392,14 @@ class BaseAPI(object):
355
392
  Headers dictionary to pass to requests
356
393
  """
357
394
 
358
- def raise_not_found():
395
+ def raise_not_found() -> ty.NoReturn:
359
396
  msg = _("%s not found") % value
360
397
  raise exceptions.NotFound(404, msg)
361
398
 
362
399
  try:
363
400
  ret = self._request(
364
401
  'GET',
365
- "/%s/%s" % (path, value),
402
+ f"/{path}/{value}",
366
403
  headers=headers,
367
404
  ).json()
368
405
  if isinstance(ret, dict):
osc_lib/api/auth.py CHANGED
@@ -14,7 +14,9 @@
14
14
  """Authentication Library"""
15
15
 
16
16
  import argparse
17
+ import typing as ty
17
18
 
19
+ from keystoneauth1.identity import base as identity_base
18
20
  from keystoneauth1.identity.v3 import k2k
19
21
  from keystoneauth1.loading import base
20
22
 
@@ -22,16 +24,25 @@ from osc_lib import exceptions as exc
22
24
  from osc_lib.i18n import _
23
25
  from osc_lib import utils
24
26
 
27
+ if ty.TYPE_CHECKING:
28
+ from openstack import connection
29
+
25
30
 
26
31
  # Initialize the list of Authentication plugins early in order
27
32
  # to get the command-line options
28
33
  PLUGIN_LIST = None
29
34
 
35
+
36
+ class _OptionDict(ty.TypedDict):
37
+ env: str
38
+ help: str
39
+
40
+
30
41
  # List of plugin command line options
31
- OPTIONS_LIST = {}
42
+ OPTIONS_LIST: dict[str, _OptionDict] = {}
32
43
 
33
44
 
34
- def get_plugin_list():
45
+ def get_plugin_list() -> frozenset[str]:
35
46
  """Gather plugin list and cache it"""
36
47
 
37
48
  global PLUGIN_LIST
@@ -41,7 +52,7 @@ def get_plugin_list():
41
52
  return PLUGIN_LIST
42
53
 
43
54
 
44
- def get_options_list():
55
+ def get_options_list() -> dict[str, _OptionDict]:
45
56
  """Gather plugin options so the help action has them available"""
46
57
 
47
58
  global OPTIONS_LIST
@@ -59,14 +70,16 @@ def get_options_list():
59
70
  # TODO(mhu) simplistic approach, would be better to only add
60
71
  # help texts if they vary from one auth plugin to another
61
72
  # also the text rendering is ugly in the CLI ...
62
- OPTIONS_LIST[os_name]['help'] += 'With %s: %s\n' % (
63
- plugin_name,
64
- o.help,
73
+ OPTIONS_LIST[os_name]['help'] += (
74
+ f'With {plugin_name}: {o.help}\n'
65
75
  )
66
76
  return OPTIONS_LIST
67
77
 
68
78
 
69
- def check_valid_authorization_options(options, auth_plugin_name):
79
+ def check_valid_authorization_options(
80
+ options: 'connection.Connection',
81
+ auth_plugin_name: str,
82
+ ) -> None:
70
83
  """Validate authorization options, and provide helpful error messages."""
71
84
  if (
72
85
  options.auth.get('project_id')
@@ -87,16 +100,15 @@ def check_valid_authorization_options(options, auth_plugin_name):
87
100
  )
88
101
 
89
102
 
90
- def check_valid_authentication_options(options, auth_plugin_name):
91
- """Validate authentication options, and provide helpful error messages
92
-
93
- :param required_scope: indicate whether a scoped token is required
94
-
95
- """
96
-
103
+ def check_valid_authentication_options(
104
+ options: 'connection.Connection',
105
+ auth_plugin_name: str,
106
+ ) -> None:
107
+ """Validate authentication options, and provide helpful error messages."""
97
108
  # Get all the options defined within the plugin.
98
- plugin_opts = base.get_plugin_options(auth_plugin_name)
99
- plugin_opts = {opt.dest: opt for opt in plugin_opts}
109
+ plugin_opts = {
110
+ opt.dest: opt for opt in base.get_plugin_options(auth_plugin_name)
111
+ }
100
112
 
101
113
  # NOTE(aloga): this is an horrible hack. We need a way to specify the
102
114
  # required options in the plugins. Using the "required" argument for
@@ -142,7 +154,9 @@ def check_valid_authentication_options(options, auth_plugin_name):
142
154
  )
143
155
 
144
156
 
145
- def build_auth_plugins_option_parser(parser):
157
+ def build_auth_plugins_option_parser(
158
+ parser: argparse.ArgumentParser,
159
+ ) -> argparse.ArgumentParser:
146
160
  """Auth plugins options builder
147
161
 
148
162
  Builds dynamically the list of options expected by each available
@@ -177,7 +191,7 @@ def build_auth_plugins_option_parser(parser):
177
191
  if 'tenant' not in o:
178
192
  parser.add_argument(
179
193
  '--os-' + o,
180
- metavar='<auth-%s>' % o,
194
+ metavar=f'<auth-{o}>',
181
195
  dest=o.replace('-', '_'),
182
196
  default=envs.get(
183
197
  OPTIONS_LIST[o]['env'],
@@ -207,13 +221,13 @@ def build_auth_plugins_option_parser(parser):
207
221
 
208
222
 
209
223
  def get_keystone2keystone_auth(
210
- local_auth,
211
- service_provider,
212
- project_id=None,
213
- project_name=None,
214
- project_domain_id=None,
215
- project_domain_name=None,
216
- ):
224
+ local_auth: identity_base.BaseIdentityPlugin,
225
+ service_provider: str,
226
+ project_id: ty.Optional[str] = None,
227
+ project_name: ty.Optional[str] = None,
228
+ project_domain_id: ty.Optional[str] = None,
229
+ project_domain_name: ty.Optional[str] = None,
230
+ ) -> k2k.Keystone2Keystone:
217
231
  """Return Keystone 2 Keystone authentication for service provider.
218
232
 
219
233
  :param local_auth: authentication to use with the local Keystone
osc_lib/api/utils.py CHANGED
@@ -13,13 +13,18 @@
13
13
 
14
14
  """API Utilities Library"""
15
15
 
16
+ import typing as ty
17
+
18
+
19
+ _T = ty.TypeVar('_T', bound=list[ty.Any])
20
+
16
21
 
17
22
  def simple_filter(
18
- data=None,
19
- attr=None,
20
- value=None,
21
- property_field=None,
22
- ):
23
+ data: ty.Optional[_T] = None,
24
+ attr: ty.Optional[str] = None,
25
+ value: ty.Optional[str] = None,
26
+ property_field: ty.Optional[str] = None,
27
+ ) -> ty.Optional[_T]:
23
28
  """Filter a list of dicts
24
29
 
25
30
  :param list data:
@@ -14,7 +14,9 @@
14
14
  """OpenStackConfig subclass for argument compatibility"""
15
15
 
16
16
  import logging
17
+ import typing as ty
17
18
 
19
+ from keystoneauth1.loading import identity as ksa_loading
18
20
  from openstack.config import exceptions as sdk_exceptions
19
21
  from openstack.config import loader as config
20
22
  from oslo_utils import strutils
@@ -23,10 +25,12 @@ from oslo_utils import strutils
23
25
  LOG = logging.getLogger(__name__)
24
26
 
25
27
 
26
- # Sublcass OpenStackConfig in order to munge config values
28
+ # Subclass OpenStackConfig in order to munge config values
27
29
  # before auth plugins are loaded
28
- class OSC_Config(config.OpenStackConfig):
29
- def _auth_select_default_plugin(self, config):
30
+ class OSC_Config(config.OpenStackConfig): # type: ignore
31
+ def _auth_select_default_plugin(
32
+ self, config: dict[str, ty.Any]
33
+ ) -> dict[str, ty.Any]:
30
34
  """Select a default plugin based on supplied arguments
31
35
 
32
36
  Migrated from auth.select_auth_plugin()
@@ -56,10 +60,12 @@ class OSC_Config(config.OpenStackConfig):
56
60
  if not config.get('auth_type', None):
57
61
  config['auth_type'] = 'password'
58
62
 
59
- LOG.debug("Auth plugin %s selected" % config['auth_type'])
63
+ LOG.debug("Auth plugin {} selected".format(config['auth_type']))
60
64
  return config
61
65
 
62
- def _auth_v2_arguments(self, config):
66
+ def _auth_v2_arguments(
67
+ self, config: dict[str, ty.Any]
68
+ ) -> dict[str, ty.Any]:
63
69
  """Set up v2-required arguments from v3 info
64
70
 
65
71
  Migrated from auth.build_auth_params()
@@ -72,40 +78,49 @@ class OSC_Config(config.OpenStackConfig):
72
78
  config['auth']['tenant_name'] = config['auth']['project_name']
73
79
  return config
74
80
 
75
- def _auth_v2_ignore_v3(self, config):
81
+ def _auth_v2_ignore_v3(
82
+ self, config: dict[str, ty.Any]
83
+ ) -> dict[str, ty.Any]:
76
84
  """Remove v3 arguments if present for v2 plugin
77
85
 
78
86
  Migrated from clientmanager.setup_auth()
79
87
  """
80
-
81
88
  # NOTE(hieulq): If USER_DOMAIN_NAME, USER_DOMAIN_ID, PROJECT_DOMAIN_ID
82
89
  # or PROJECT_DOMAIN_NAME is present and API_VERSION is 2.0, then
83
90
  # ignore all domain related configs.
84
- if str(config.get('identity_api_version', '')).startswith(
85
- '2'
86
- ) and config.get('auth_type').endswith('password'):
87
- domain_props = [
88
- 'project_domain_id',
89
- 'project_domain_name',
90
- 'user_domain_id',
91
- 'user_domain_name',
92
- ]
93
- for prop in domain_props:
94
- if config['auth'].pop(prop, None) is not None:
95
- if config.get('cloud'):
96
- LOG.warning(
97
- "Ignoring domain related config %s for %s"
98
- "because identity API version is 2.0"
99
- % (prop, config['cloud'])
100
- )
101
- else:
102
- LOG.warning(
103
- "Ignoring domain related config %s because"
104
- " identity API version is 2.0" % prop
91
+ if not str(config.get('identity_api_version', '')).startswith('2'):
92
+ return config
93
+
94
+ if not config.get('auth_type') or not config['auth_type'].endswith(
95
+ 'password'
96
+ ):
97
+ return config
98
+
99
+ domain_props = [
100
+ 'project_domain_id',
101
+ 'project_domain_name',
102
+ 'user_domain_id',
103
+ 'user_domain_name',
104
+ ]
105
+ for prop in domain_props:
106
+ if config['auth'].pop(prop, None) is not None:
107
+ if config.get('cloud'):
108
+ LOG.warning(
109
+ "Ignoring domain related config {} for {}"
110
+ "because identity API version is 2.0".format(
111
+ prop, config['cloud']
105
112
  )
113
+ )
114
+ else:
115
+ LOG.warning(
116
+ f"Ignoring domain related config {prop} because"
117
+ " identity API version is 2.0"
118
+ )
106
119
  return config
107
120
 
108
- def _auth_default_domain(self, config):
121
+ def _auth_default_domain(
122
+ self, config: dict[str, ty.Any]
123
+ ) -> dict[str, ty.Any]:
109
124
  """Set a default domain from available arguments
110
125
 
111
126
  Migrated from clientmanager.setup_auth()
@@ -146,7 +161,7 @@ class OSC_Config(config.OpenStackConfig):
146
161
  config['auth']['user_domain_id'] = default_domain
147
162
  return config
148
163
 
149
- def auth_config_hook(self, config):
164
+ def auth_config_hook(self, config: dict[str, ty.Any]) -> dict[str, ty.Any]:
150
165
  """Allow examination of config values before loading auth plugin
151
166
 
152
167
  OpenStackClient will override this to perform additional checks
@@ -164,7 +179,11 @@ class OSC_Config(config.OpenStackConfig):
164
179
  )
165
180
  return config
166
181
 
167
- def _validate_auth(self, config, loader, fixed_argparse=None):
182
+ def _validate_auth(
183
+ self,
184
+ config: dict[str, ty.Any],
185
+ loader: ksa_loading.BaseIdentityLoader[ty.Any],
186
+ ) -> dict[str, ty.Any]:
168
187
  """Validate auth plugin arguments"""
169
188
  # May throw a keystoneauth1.exceptions.NoMatchingPlugin
170
189
 
@@ -204,9 +223,9 @@ class OSC_Config(config.OpenStackConfig):
204
223
  # Prefer the plugin configuration dest value if the value's key
205
224
  # is marked as depreciated.
206
225
  if p_opt.dest is None:
207
- config['auth'][
208
- p_opt.name.replace('-', '_')
209
- ] = winning_value
226
+ config['auth'][p_opt.name.replace('-', '_')] = (
227
+ winning_value
228
+ )
210
229
  else:
211
230
  config['auth'][p_opt.dest] = winning_value
212
231
 
@@ -228,7 +247,8 @@ class OSC_Config(config.OpenStackConfig):
228
247
 
229
248
  return config
230
249
 
231
- def load_auth_plugin(self, config):
250
+ # TODO(stephenfin): Add type once we have typing for SDK
251
+ def load_auth_plugin(self, config: dict[str, ty.Any]) -> ty.Any:
232
252
  """Get auth plugin and validate args"""
233
253
 
234
254
  loader = self._get_auth_loader(config)
@@ -15,53 +15,55 @@
15
15
 
16
16
  """Formattable column for specify content type"""
17
17
 
18
+ import typing as ty
19
+
18
20
  from cliff import columns
19
21
 
20
22
  from osc_lib import utils
21
23
 
22
24
 
23
- class DictColumn(columns.FormattableColumn):
25
+ class DictColumn(columns.FormattableColumn[dict[str, ty.Any]]):
24
26
  """Format column for dict content"""
25
27
 
26
- def human_readable(self):
28
+ def human_readable(self) -> str:
27
29
  return utils.format_dict(self._value)
28
30
 
29
- def machine_readable(self):
31
+ def machine_readable(self) -> dict[str, ty.Any]:
30
32
  return dict(self._value or {})
31
33
 
32
34
 
33
- class DictListColumn(columns.FormattableColumn):
35
+ class DictListColumn(columns.FormattableColumn[dict[str, list[ty.Any]]]):
34
36
  """Format column for dict, key is string, value is list"""
35
37
 
36
- def human_readable(self):
37
- return utils.format_dict_of_list(self._value)
38
+ def human_readable(self) -> str:
39
+ return utils.format_dict_of_list(self._value) or ''
38
40
 
39
- def machine_readable(self):
41
+ def machine_readable(self) -> dict[str, list[ty.Any]]:
40
42
  return dict(self._value or {})
41
43
 
42
44
 
43
- class ListColumn(columns.FormattableColumn):
45
+ class ListColumn(columns.FormattableColumn[list[ty.Any]]):
44
46
  """Format column for list content"""
45
47
 
46
- def human_readable(self):
47
- return utils.format_list(self._value)
48
+ def human_readable(self) -> str:
49
+ return utils.format_list(self._value) or ''
48
50
 
49
- def machine_readable(self):
51
+ def machine_readable(self) -> list[ty.Any]:
50
52
  return [x for x in self._value or []]
51
53
 
52
54
 
53
- class ListDictColumn(columns.FormattableColumn):
55
+ class ListDictColumn(columns.FormattableColumn[list[dict[str, ty.Any]]]):
54
56
  """Format column for list of dict content"""
55
57
 
56
- def human_readable(self):
57
- return utils.format_list_of_dicts(self._value)
58
+ def human_readable(self) -> str:
59
+ return utils.format_list_of_dicts(self._value) or ''
58
60
 
59
- def machine_readable(self):
61
+ def machine_readable(self) -> list[dict[str, ty.Any]]:
60
62
  return [dict(x) for x in self._value or []]
61
63
 
62
64
 
63
- class SizeColumn(columns.FormattableColumn):
65
+ class SizeColumn(columns.FormattableColumn[ty.Union[int, float]]):
64
66
  """Format column for file size content"""
65
67
 
66
- def human_readable(self):
68
+ def human_readable(self) -> str:
67
69
  return utils.format_size(self._value)
osc_lib/cli/identity.py CHANGED
@@ -11,13 +11,19 @@
11
11
  # under the License.
12
12
  #
13
13
 
14
+ import argparse
15
+ import typing as ty
16
+
17
+ from openstack import connection
14
18
  from openstack import exceptions
15
19
  from openstack.identity.v3 import project
16
20
 
17
21
  from osc_lib.i18n import _
18
22
 
19
23
 
20
- def add_project_owner_option_to_parser(parser):
24
+ def add_project_owner_option_to_parser(
25
+ parser: argparse.ArgumentParser,
26
+ ) -> None:
21
27
  """Register project and project domain options.
22
28
 
23
29
  :param parser: argparse.Argument parser object.
@@ -38,7 +44,13 @@ def add_project_owner_option_to_parser(parser):
38
44
  )
39
45
 
40
46
 
41
- def find_project(sdk_connection, name_or_id, domain_name_or_id=None):
47
+ # TODO(stephenfin): This really doesn't belong here. This should be part of
48
+ # openstacksdk itself.
49
+ def find_project(
50
+ sdk_connection: connection.Connection,
51
+ name_or_id: str,
52
+ domain_name_or_id: ty.Optional[str] = None,
53
+ ) -> project.Project:
42
54
  """Find a project by its name name or ID.
43
55
 
44
56
  If Forbidden to find the resource (a common case if the user does not have
@@ -53,7 +65,6 @@ def find_project(sdk_connection, name_or_id, domain_name_or_id=None):
53
65
  This can be used when there are multiple projects with a same name.
54
66
  :returns: the project object found
55
67
  :rtype: `openstack.identity.v3.project.Project`
56
-
57
68
  """
58
69
  try:
59
70
  if domain_name_or_id: