Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit489b0d3

Browse files
authored
Merge pull request#1481 from JohnVillalovos/jlvillal/no_getmro
chore: use built-in function issubclass() instead of getmro()
2 parents56770ce +81f6386 commit489b0d3

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

‎gitlab/v4/cli.py‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
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-
importinspect
2019
importoperator
2120
importsys
2221

@@ -72,7 +71,7 @@ def do_custom(self):
7271
ifself.mgr._from_parent_attrs:
7372
forkinself.mgr._from_parent_attrs:
7473
data[k]=self.args[k]
75-
ifgitlab.mixins.GetWithoutIdMixinnotininspect.getmro(self.cls):
74+
ifnotissubclass(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
defdo_get(self):
105104
id=None
106-
ifgitlab.mixins.GetWithoutIdMixinnotininspect.getmro(self.mgr_cls):
105+
ifnotissubclass(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
defdo_update(self):
122121
id=None
123-
ifgitlab.mixins.GetWithoutIdMixinnotininspect.getmro(self.mgr_cls):
122+
ifnotissubclass(self.mgr_cls,gitlab.mixins.GetWithoutIdMixin):
124123
id=self.args.pop(self.cls._id_attr)
125124
try:
126125
returnself.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
ifaction_name=="get":
163-
ifgitlab.mixins.GetWithoutIdMixinnotininspect.getmro(cls):
162+
ifnotissubclass(cls,gitlab.mixins.GetWithoutIdMixin):
164163
ifcls._id_attrisnotNone:
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-
ifgitlab.mixins.GetWithoutIdMixinnotininspect.getmro(cls):
212+
ifnotissubclass(cls,gitlab.mixins.GetWithoutIdMixin):
214213
ifcls._id_attrisnotNone:
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
forclsingitlab.v4.objects.__dict__.values():
271-
try:
272-
ifgitlab.base.RESTManagerininspect.getmro(cls):
273-
ifcls._obj_clsisnotNone:
274-
classes.append(cls._obj_cls)
275-
exceptAttributeError:
276-
pass
270+
ifnotisinstance(cls,type):
271+
continue
272+
ifissubclass(cls,gitlab.base.RESTManager):
273+
ifcls._obj_clsisnotNone:
274+
classes.append(cls._obj_cls)
277275
classes.sort(key=operator.attrgetter("__name__"))
278276

279277
forclsinclasses:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp