Skip to content

Commit

Permalink
+ [apiclient] add docstring for BaseManager
Browse files Browse the repository at this point in the history
  • Loading branch information
lanfon72 committed Nov 23, 2023
1 parent fed60fc commit db1a87e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apiclient/harvester_api/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ def merge_dict(src, dest):


class BaseManager:
#: Be used to store sub classes of BaseManager,
#: the attribute will be automatically updated by `__init_subclass__`
#: Type: Dict[Type[BaseManager], List[Type[BaseManager]]]
_sub_classes = dict()

#: Be used to adjust whether the class is support to specific version,
#: the value should be semantic version and re-defined in derived class
#: Type: str
support_to = "0.0.0"

@classmethod
Expand All @@ -25,6 +32,12 @@ def is_support(cls, target_version):

@classmethod
def for_version(cls, version):
''' Return a (most suitable) derived class `cls` which `cls.is_support` is True
Otherwise, return the class itself.
:param str version: the version string going to seek
:return Type[cls]: the most suitable class for version
'''
for c in sorted(cls._sub_classes.get(cls, []),
reverse=True, key=lambda x: parse_version(x.support_to).release):
if c.is_support(version):
Expand Down

0 comments on commit db1a87e

Please sign in to comment.