From 31a60b12ffa12eb3163fd3f2ac39b08b4620e230 Mon Sep 17 00:00:00 2001 From: Daniel Goldberg Date: Tue, 12 Nov 2019 20:07:48 +0200 Subject: [PATCH] Fix typing in factory method --- monkey/infection_monkey/utils/plugins/plugin.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/utils/plugins/plugin.py b/monkey/infection_monkey/utils/plugins/plugin.py index 474afbba8..21d3134bf 100644 --- a/monkey/infection_monkey/utils/plugins/plugin.py +++ b/monkey/infection_monkey/utils/plugins/plugin.py @@ -4,7 +4,7 @@ import logging from abc import ABCMeta, abstractmethod from os.path import dirname, basename, isfile, join import glob -from typing import Sequence +from typing import Sequence, TypeVar, Type LOG = logging.getLogger(__name__) @@ -14,6 +14,9 @@ def _get_candidate_files(base_package_file): return [basename(f)[:-3] for f in files if isfile(f) and not f.endswith('__init__.py')] +Plugin_type = TypeVar('Plugin_type', bound='Plugin') + + class Plugin(metaclass=ABCMeta): @staticmethod @@ -22,7 +25,7 @@ class Plugin(metaclass=ABCMeta): raise NotImplementedError() @classmethod - def get_instances(cls) -> Sequence[object]: + def get_instances(cls) -> Sequence[Type[Plugin_type]]: """ Returns the type objects from base_package_spec. base_package name and file must refer to the same package otherwise bad results