You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type hint on ListMixin.list says that it returns a Union[base.RESTObjectList, List[base.RestObject]] but this is too strict; each concrete subclass of ListMixin will actually return a Sequence[self._obj_cls].
I'm somewhat new to Python type hints but could this be solved by introducing a type variable and connecting it to both _obj_cls and list()?
I don't think it is too strict. In fact I think it is too loose. Because if you get a list of users the type-checkers will think it is a List[RestObject] when in reality it is a List[gitlab.v4.objects.Users] 😟 NOTE: gitlab.v4.objects.Users is derived from RestObject.
So far we have not figured out an easy/elegant way to solve this problem. One idea is to do like we do with the get methods and add a wrapper method to every class but the RESTObjectList kind of causes problems there...
I'm not sure. mypy raised 800 errors when I tried that patch?
Basically errors like this:
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "GetMixin" is incompatible with definition in base class "ListMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "GetMixin" is incompatible with definition in base class "CreateMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "GetMixin" is incompatible with definition in base class "UpdateMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "GetMixin" is incompatible with definition in base class "DeleteMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "ListMixin" is incompatible with definition in base class "CreateMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "ListMixin" is incompatible with definition in base class "UpdateMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "ListMixin" is incompatible with definition in base class "DeleteMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "CreateMixin" is incompatible with definition in base class "UpdateMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "CreateMixin" is incompatible with definition in base class "DeleteMixin"
gitlab/v4/objects/groups.py:254: error: Definition of "_parent" in base class "UpdateMixin" is incompatible with definition in base class "DeleteMixin"
Activity
JohnVillalovos commentedon Jun 9, 2022
I don't think it is too strict. In fact I think it is too loose. Because if you get a list of users the type-checkers will think it is a
List[RestObject]when in reality it is aList[gitlab.v4.objects.Users]😟 NOTE:gitlab.v4.objects.Usersis derived fromRestObject.So far we have not figured out an easy/elegant way to solve this problem. One idea is to do like we do with the
getmethods and add a wrapper method to every class but theRESTObjectListkind of causes problems there...vectro commentedon Jun 10, 2022
John, I think this could be solved with generic class objects. Would something like this patch do the job?
https://gist.github.com/vectro/fa5a88b320407f400da2ed54aecfa03f
JohnVillalovos commentedon Jun 10, 2022
I'm not sure.
mypyraised 800 errors when I tried that patch?Basically errors like this:
vectro commentedon Jun 11, 2022
Hmm, that's interesting. I don't see that error on my end. What mypy are you using? I have 0.812 with default settings.
JohnVillalovos commentedon Jun 11, 2022
I used:
And we are using
mypy==0.960vectro commentedon Jun 11, 2022
It looks like mypy just doesn't like the redundant type hints on the intermediate abstract classes. If you move these to the base class these errors go away. See here for a sketch: https://gist.github.com/vectro/c6b6dd921ddf7fded5203a97e066e904
Looks like mypy folks are still figuring out what to do about diamond inheritance: python/mypy#1065
JohnVillalovos commentedon Jun 11, 2022
If you want, maybe the best way forward would be for you to propose a pull request. You can always mark it as "draft" if you like.
That would make it easier to review and see that it passes the checks.
vectro commentedon Jun 12, 2022
@JohnVillalovos, sure, thanks, done.
nejch commentedon Jun 13, 2022
@vectro as I said in the PR it's best to follow the versions we track here by using our tox setup :)