a *Na@s0dZddlZddlZddlZddZddZdS)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. NcCsGdddt}Gddd|}tt"}Gddd||}Wdn1sR0Yd|vslJGd d d ||}dS) z2Test case to demonstrate the TypeError that occursc@seZdZeeddddZdS)z#test_show_issue..RESTObjectN)managerattrsreturncSsdS)N)selfrrrrv/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__strintrrrrr RESTObject7src@s eZdZdS)ztest_show_issue..MixinNr r r rrrrMixin;src@s eZdZdS)z&test_show_issue..Wrongv4ObjectNrrrrr Wrongv4Object@srNZMROc@s eZdZdS)z(test_show_issue..Correctv4ObjectNrrrrrCorrectv4ObjectKsr)objectpytestZraises TypeErrorZexconly)rrexc_inforrrrrtest_show_issue4s  0rc Csg}ttjjD]\}}t|s&qt|D]\}}t|sDq0|jdkrPq0|}d}t |ddD]\}}|jdkrhd}|j } qh|r0t |} |djdkr0| d|d| d | d q0qd |} |rJ| d S) zEnsure 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)startTzclass definition for z in file z must have z* as the last class in the class definition N)inspect getmembersgitlabZv4Zobjectsismoduleisclassr mro enumerater getfileappendjoin) Zfailed_messages module_nameZ module_value class_nameZ class_valuer!Zhas_basecountobjZbase_classnamefilenameZ failed_msgrrr test_mrosOs2      r+)__doc__rrZgitlab.v4.objectsrrr+rrrrs ,