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
Yes, that is a current limitation of our type-hints. For the get methods we have forced each manager to define a get method which has the correct type-hint. But we would like to have a better way to handle it for all methods without needing to define each one in every manager.
Yes, that is a current limitation of our type-hints. For the get methods we have forced each manager to define a get method which has the correct type-hint. But we would like to have a better way to handle it for all methods without needing to define each one in every manager.
I prototyped using a Protocol for the RESTManager. Apparently there is a comment Derived class must define ``_path`` and ``_obj_cls``. so having separate class for the manager without _obj_cls is not needed according to this comment. Not sure why the _path is marked as Optional though.
I also used the @abstractmethod in the protocol to ensure that subclasses define the _path and _obj_cls and it seems to be type checked but only when the class is initialised but not then defined.
Activity
JohnVillalovos commentedon Sep 13, 2022
Yes, that is a current limitation of our type-hints. For the
getmethods we have forced each manager to define agetmethod which has the correct type-hint. But we would like to have a better way to handle it for all methods without needing to define each one in every manager.vectro commentedon Jan 18, 2023
Is this a duplicate of #2062?
igorp-collabora commentedon Jan 2, 2025
Wouldn't a generic protocol work for this, like mypy documentation recommends?
I made a small script to test if type checker will properly resolve the type:
When I ran mypy 1.14.0 it seemed to properly resolve the types:
igorp-collabora commentedon Jan 3, 2025
I made a table of the Mixins to the attributes used. This is useful for defining the protocols.
self.path,self.gitlabself._obj_cls,self.path,self.gitlabself._obj_cls,self.path,self.gitlabself.manager,self.encoded_id,self._update_attrs()self._obj_cls,self.path,self.gitlabself._obj_cls,self.path,self.gitlab,self._typesself._obj_cls,self.path,self.gitlabself._obj_cls,self.path,self.gitlabself.path,self.gitlabself.manager,self.encoded_idself.manager,self.encoded_idself.manager,self.encoded_id,self._update_attrsself.manager,self.encoded_id,self._update_attrsself.managerself.path,self.gitlabself.manager,self.encoded_id,self._update_attrsself.manager,self.encoded_id,self._update_attrsself.manager,self.encoded_id,self.manager,self.encoded_id,self.attributesself.manager,self.encoded_idself.manager,self.encoded_idself.manager,self.attributes,self._upload_pathAs you can see generally there are 2 groups of attributes used:
self._obj_cls,self.path,self.gitlabandself.manager,self.encoded_idigorp-collabora commentedon Jan 8, 2025
I prototyped using a Protocol for the
RESTManager. Apparently there is a commentDerived class must define ``_path`` and ``_obj_cls``.so having separate class for the manager without _obj_cls is not needed according to this comment. Not sure why the_pathis marked as Optional though.I also used the
@abstractmethodin the protocol to ensure that subclasses define the_pathand_obj_clsand it seems to be type checked but only when the class is initialised but not then defined.The Bad class that does not define the
_pathor_obj_clsso it type errors on instantiating: