1616# You should have received a copy of the GNU Lesser General Public License
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
19- import inspect
2019import operator
2120import sys
2221
@@ -72,7 +71,7 @@ def do_custom(self):
7271 if self .mgr ._from_parent_attrs :
7372 for k in self .mgr ._from_parent_attrs :
7473 data [k ] = self .args [k ]
75- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .cls ):
74+ if not issubclass (self .cls , gitlab . mixins . GetWithoutIdMixin ):
7675 data [self .cls ._id_attr ] = self .args .pop (self .cls ._id_attr )
7776 o = self .cls (self .mgr , data )
7877 method_name = self .action .replace ("-" , "_" )
@@ -103,7 +102,7 @@ def do_list(self):
103102
104103 def do_get (self ):
105104 id = None
106- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .mgr_cls ):
105+ if not issubclass (self .mgr_cls , gitlab . mixins . GetWithoutIdMixin ):
107106 id = self .args .pop (self .cls ._id_attr )
108107
109108 try :
@@ -120,7 +119,7 @@ def do_delete(self):
120119
121120 def do_update (self ):
122121 id = None
123- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .mgr_cls ):
122+ if not issubclass (self .mgr_cls , gitlab . mixins . GetWithoutIdMixin ):
124123 id = self .args .pop (self .cls ._id_attr )
125124 try :
126125 return self .mgr .update (id , self .args )
@@ -160,7 +159,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
160159 sub_parser_action .add_argument ("--%s" % id_attr , required = True )
161160
162161 if action_name == "get" :
163- if gitlab .mixins .GetWithoutIdMixin not in inspect . getmro ( cls ):
162+ if not issubclass ( cls , gitlab .mixins .GetWithoutIdMixin ):
164163 if cls ._id_attr is not None :
165164 id_attr = cls ._id_attr .replace ("_" , "-" )
166165 sub_parser_action .add_argument ("--%s" % id_attr , required = True )
@@ -210,7 +209,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
210209 sub_parser_action .add_argument ("--sudo" , required = False )
211210
212211 # We need to get the object somehow
213- if gitlab .mixins .GetWithoutIdMixin not in inspect . getmro ( cls ):
212+ if not issubclass ( cls , gitlab .mixins .GetWithoutIdMixin ):
214213 if cls ._id_attr is not None :
215214 id_attr = cls ._id_attr .replace ("_" , "-" )
216215 sub_parser_action .add_argument ("--%s" % id_attr , required = True )
@@ -268,12 +267,11 @@ def extend_parser(parser):
268267 # populate argparse for all Gitlab Object
269268 classes = []
270269 for cls in gitlab .v4 .objects .__dict__ .values ():
271- try :
272- if gitlab .base .RESTManager in inspect .getmro (cls ):
273- if cls ._obj_cls is not None :
274- classes .append (cls ._obj_cls )
275- except AttributeError :
276- pass
270+ if not isinstance (cls , type ):
271+ continue
272+ if issubclass (cls , gitlab .base .RESTManager ):
273+ if cls ._obj_cls is not None :
274+ classes .append (cls ._obj_cls )
277275 classes .sort (key = operator .attrgetter ("__name__" ))
278276
279277 for cls in classes :
0 commit comments