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
feat(api): Make RESTManager generic on RESTObject class
Currently mixins like ListMixin are type hinted to return base
RESTObject instead of a specific class like `MergeRequest`.
The GetMixin and GetWithoutIdMixin solve this problem by defining
a new `get` method for every defined class. However, this creates
a lot of duplicated code.
Make RESTManager use `typing.Generic` as its base class and use
and assign the declared TypeVar to the `_obj_cls` attribute as
a type of the passed class.
Make both `_obj_cls` and `_path` attributes an abstract properties
so that type checkers can check that those attributes were properly
defined in subclasses. Mypy will only check then the class is
instantiated which makes non-final subclasses possible.
Unfortunately pylint will check the declarations not instantiations
so add `# pylint: disable=abstract-method` comments to all non-final
subclasses like ListMixin.
Make `_path` attribute always be `str` instead of sometimes `None`.
This eliminates unnecessary type checks.
Change all mixins like ListMixin or GetMixin to a subclass. This makes
the attribute declarations much cleaner as for example `_list_filters`
is now the only attribute defined by ListMixin.
Change SidekiqManager to not inherit from RESTManager and only
copy its `__init__` method. This is because SidekiqManager never
was a real manager and does not define `_path` or `_obj_cls`.
Delete `tests/unit/meta/test_ensure_type_hints.py` file as the `get`
method is no required to be defined for every class.
Signed-off-by: Igor Ponomarev <igor.ponomarev@collabora.com>
0 commit comments