a Æ*Na§ã@s0dZddlZddlZddlZdd„Zdd„ZdS)aa Ensure objects defined in gitlab.v4.objects have REST* as last item in class definition Original notes by John L. Villalovos An example of an incorrect definition: class ProjectPipeline(RESTObject, RefreshMixin, ObjectDeleteMixin): ^^^^^^^^^^ This should be at the end. Correct way would be: class ProjectPipeline(RefreshMixin, ObjectDeleteMixin, RESTObject): Correctly at the end ^^^^^^^^^^ Why this is an issue: When we do type-checking for gitlab/mixins.py we make RESTObject or RESTManager the base class for the mixins Here is how our classes look when type-checking: class RESTObject(object): def __init__(self, manager: "RESTManager", attrs: Dict[str, Any]) -> None: ... class Mixin(RESTObject): ... # Wrong ordering here class Wrongv4Object(RESTObject, RefreshMixin): ... If we actually ran this in Python we would get the following error: class Wrongv4Object(RESTObject, Mixin): TypeError: Cannot create a consistent method resolution order (MRO) for bases RESTObject, Mixin When we are type-checking it fails to understand the class Wrongv4Object and thus we can't type check it correctly. Almost all classes in gitlab/v4/objects/*py were already correct before this check was added. éNcCs‚Gdd„dtƒ}Gdd„d|ƒ}t t¡�"}Gdd„d||ƒ}Wdƒn1sR0Yd| ¡vslJ‚Gd d „d ||ƒ}dS) z2Test case to demonstrate the TypeError that occursc@seZdZeeddœdd„ZdS)z#test_show_issue..RESTObjectN)ÚmanagerÚattrsÚreturncSsdS)N©)Úselfrrrrúv/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/tests/unit/objects/test_mro.pyÚ__init__8sz,test_show_issue..RESTObject.__init__)Ú__name__Ú __module__Ú __qualname__ÚstrÚintrrrrrÚ RESTObject7src@s eZdZdS)ztest_show_issue..MixinN©r r r rrrrÚMixin;src@s eZdZdS)z&test_show_issue..Wrongv4ObjectNrrrrrÚ Wrongv4Object@srNZMROc@s eZdZdS)z(test_show_issue..Correctv4ObjectNrrrrrÚCorrectv4ObjectKsr)ÚobjectÚpytestZraisesÚ TypeErrorZexconly)rrÚexc_inforrrrrÚtest_show_issue4s  0rc CsÞg}t tjj¡D]°\}}t |¡s&qt |¡D]�\}}t |¡sDq0|jdkrPq0| ¡}d}t |dd�D]\}}|jdkrhd}|j } qh|r0t  |¡} |djdkr0|  d|›d| ›d | ›d �¡q0qd   |¡} |rÚJ| ƒ‚d S) z¸Ensure objects defined in gitlab.v4.objects have REST* as last item in class definition. We do this as we need to ensure the MRO (Method Resolution Order) is correct. z gitlab.baseFé)ÚstartTéþÿÿÿzclass definition for z in file z must have z* as the last class in the class definitionÚ N)ÚinspectÚ getmembersÚgitlabZv4ZobjectsÚismoduleÚisclassr ÚmroÚ enumerater ÚgetfileÚappendÚjoin) Zfailed_messagesÚ module_nameZ module_valueÚ class_nameZ class_valuer!Zhas_baseÚcountÚobjZbase_classnameÚfilenameZ failed_msgrrrÚ test_mrosOs2     ÿþ r+)Ú__doc__rrZgitlab.v4.objectsrrr+rrrrÚs ,