1212#
1313
1414import abc
15+ import argparse
16+ from collections .abc import Generator
1517import contextlib
1618import logging
1719from typing import Any
1820
19- from cliff import _argparse
2021import openstack .exceptions
2122from osc_lib .cli import parseractions
2223from osc_lib import exceptions
4344
4445
4546@contextlib .contextmanager
46- def check_missing_extension_if_error (client_manager , attrs ):
47+ def check_missing_extension_if_error (
48+ client_manager : Any , attrs : dict [str , Any ]
49+ ) -> Generator [None , None , None ]:
4750 # If specified option requires extension, then try to
4851 # find out if it exists. If it does not exist,
4952 # then an exception with the appropriate message
@@ -68,7 +71,7 @@ class NetDetectionMixin(command.Command, metaclass=abc.ABCMeta):
6871 """
6972
7073 @property
71- def _network_type (self ):
74+ def _network_type (self ) -> str | None :
7275 """Discover whether the running cloud is using neutron or nova-network.
7376
7477 :return:
@@ -96,31 +99,31 @@ def _network_type(self):
9699 return self ._net_type
97100
98101 @property
99- def is_neutron (self ):
102+ def is_neutron (self ) -> bool :
100103 return self ._network_type is _NET_TYPE_NEUTRON
101104
102105 @property
103- def is_nova_network (self ):
106+ def is_nova_network (self ) -> bool :
104107 return self ._network_type is _NET_TYPE_COMPUTE
105108
106109 @property
107- def is_docs_build (self ):
110+ def is_docs_build (self ) -> bool :
108111 return self ._network_type is None
109112
110- def enhance_help_neutron (self , _help ) :
113+ def enhance_help_neutron (self , _help : str ) -> str :
111114 if self .is_docs_build :
112115 # Why can't we say 'neutron'?
113116 return _QUALIFIER_FMT % (_help , _ ("Network version 2 only" ))
114117 return _help
115118
116- def enhance_help_nova_network (self , _help ) :
119+ def enhance_help_nova_network (self , _help : str ) -> str :
117120 if self .is_docs_build :
118121 # Why can't we say 'nova-network'?
119122 return _QUALIFIER_FMT % (_help , _ ("Compute version 2 only" ))
120123 return _help
121124
122125 @staticmethod
123- def split_help (network_help , compute_help ) :
126+ def split_help (network_help : str , compute_help : str ) -> str :
124127 return (
125128 "*{network_qualifier}:*\n {network_help}\n \n "
126129 "*{compute_qualifier}:*\n {compute_help}" .format (
@@ -133,7 +136,7 @@ def split_help(network_help, compute_help):
133136 )
134137 )
135138
136- def get_parser (self , prog_name : str ) -> _argparse .ArgumentParser :
139+ def get_parser (self , prog_name : str ) -> argparse .ArgumentParser :
137140 LOG .debug ('get_parser(%s)' , prog_name )
138141 parser = super ().get_parser (prog_name )
139142 parser = self .update_parser_common (parser )
@@ -145,19 +148,25 @@ def get_parser(self, prog_name: str) -> _argparse.ArgumentParser:
145148 parser = self .update_parser_compute (parser )
146149 return parser
147150
148- def update_parser_common (self , parser ):
151+ def update_parser_common (
152+ self , parser : argparse .ArgumentParser
153+ ) -> argparse .ArgumentParser :
149154 """Default is no updates to parser."""
150155 return parser
151156
152- def update_parser_network (self , parser ):
157+ def update_parser_network (
158+ self , parser : argparse .ArgumentParser
159+ ) -> argparse .ArgumentParser :
153160 """Default is no updates to parser."""
154161 return parser
155162
156- def update_parser_compute (self , parser ):
163+ def update_parser_compute (
164+ self , parser : argparse .ArgumentParser
165+ ) -> argparse .ArgumentParser :
157166 """Default is no updates to parser."""
158167 return parser
159168
160- def take_action (self , parsed_args ) :
169+ def take_action (self , parsed_args : argparse . Namespace ) -> Any :
161170 if self .is_neutron :
162171 return self .take_action_network (
163172 self .app .client_manager .network ,
@@ -169,11 +178,15 @@ def take_action(self, parsed_args):
169178 parsed_args ,
170179 )
171180
172- def take_action_network (self , client , parsed_args ):
181+ def take_action_network (
182+ self , client : Any , parsed_args : argparse .Namespace
183+ ) -> Any :
173184 """Override to do something useful."""
174185 pass
175186
176- def take_action_compute (self , client , parsed_args ):
187+ def take_action_compute (
188+ self , client : Any , parsed_args : argparse .Namespace
189+ ) -> Any :
177190 """Override to do something useful."""
178191 pass
179192
@@ -204,7 +217,7 @@ class NetworkAndComputeDelete(NetworkAndComputeCommand, metaclass=abc.ABCMeta):
204217
205218 resource : str
206219
207- def take_action (self , parsed_args ) :
220+ def take_action (self , parsed_args : argparse . Namespace ) -> None :
208221 ret = 0
209222 resources = getattr (parsed_args , self .resource , [])
210223
@@ -267,7 +280,7 @@ class NetworkAndComputeShowOne(
267280 arguments.
268281 """
269282
270- def take_action (self , parsed_args ) :
283+ def take_action (self , parsed_args : argparse . Namespace ) -> Any :
271284 try :
272285 if self .app .client_manager .is_network_endpoint_enabled ():
273286 return self .take_action_network (
@@ -300,7 +313,7 @@ class NeutronCommandWithExtraArgs(command.Command):
300313 'str' : str ,
301314 }
302315
303- def _get_property_converter (self , _property ) :
316+ def _get_property_converter (self , _property : dict [ str , Any ]) -> Any :
304317 if 'type' in _property :
305318 converter = self ._allowed_types_dict .get (_property ['type' ])
306319 else :
@@ -316,15 +329,17 @@ def _get_property_converter(self, _property):
316329 )
317330 return converter
318331
319- def _parse_extra_properties (self , extra_properties ):
332+ def _parse_extra_properties (
333+ self , extra_properties : list [dict [str , Any ]] | None
334+ ) -> dict [str , Any ]:
320335 result : dict [str , Any ] = {}
321336 if extra_properties :
322337 for _property in extra_properties :
323338 converter = self ._get_property_converter (_property )
324339 result [_property ['name' ]] = converter (_property ['value' ])
325340 return result
326341
327- def get_parser (self , prog_name ) :
342+ def get_parser (self , prog_name : str ) -> argparse . ArgumentParser :
328343 parser = super ().get_parser (prog_name )
329344 parser .add_argument (
330345 '--extra-property' ,
@@ -349,7 +364,9 @@ def get_parser(self, prog_name):
349364
350365
351366class NeutronUnsetCommandWithExtraArgs (NeutronCommandWithExtraArgs ):
352- def _parse_extra_properties (self , extra_properties ):
367+ def _parse_extra_properties (
368+ self , extra_properties : list [dict [str , Any ]] | None
369+ ) -> dict [str , Any ]:
353370 result : dict [str , Any ] = {}
354371 if extra_properties :
355372 for _property in extra_properties :
0 commit comments