From a820a5195c5e632f30f763e1ddb45df5a4bba62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Tue, 3 Oct 2017 22:46:33 +0200 Subject: [PATCH] Resource is an abstract class, be clear about it the consequence of this is that we need to declare the non-existent function destroy in `Resource`. As a consequence, we have to explicitly declare it in the slightly specialized classes that directly inherit from it, `DefaultResource` and `ListableResource`. We "implement" it by raising an error. This patch fixes #156, and has been once again discovered by `mypy --strict` (#131). --- iocage/lib/Resource.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/iocage/lib/Resource.py b/iocage/lib/Resource.py index 0cdd7df9..741382eb 100644 --- a/iocage/lib/Resource.py +++ b/iocage/lib/Resource.py @@ -23,6 +23,7 @@ # POSSIBILITY OF SUCH DAMAGE. import typing import os.path +import abc import libzfs @@ -41,7 +42,7 @@ import iocage.lib.Config.File # noqa: F401 -class Resource: +class Resource(metaclass=abc.ABCMeta): """ iocage resource @@ -124,6 +125,10 @@ def __init__( elif dataset is not None: self.dataset = dataset + @abc.abstractmethod + def destroy(self): + pass + @property def pool(self) -> libzfs.ZFSPool: return self.zfs.get_pool(self.dataset_name) @@ -321,6 +326,9 @@ def __init__( logger=logger ) + def destroy(self): + raise NotImplementedError("destroy unimplemented for DefaultResource") + def save(self) -> None: self.write_config(self.config.user_data) @@ -349,6 +357,9 @@ def __init__( self.filters = filters + def destroy(self): + raise NotImplementedError("destroy unimplemented for ListableResource") + def __iter__( self ) -> typing.Generator['iocage.lib.Resource.Resource', None, None]: