Skip to content

Commit a820a51

Browse files
committed
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).
1 parent e9a15d0 commit a820a51

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

iocage/lib/Resource.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# POSSIBILITY OF SUCH DAMAGE.
2424
import typing
2525
import os.path
26+
import abc
2627

2728
import libzfs
2829

@@ -41,7 +42,7 @@
4142
import iocage.lib.Config.File # noqa: F401
4243

4344

44-
class Resource:
45+
class Resource(metaclass=abc.ABCMeta):
4546
"""
4647
iocage resource
4748
@@ -124,6 +125,10 @@ def __init__(
124125
elif dataset is not None:
125126
self.dataset = dataset
126127

128+
@abc.abstractmethod
129+
def destroy(self):
130+
pass
131+
127132
@property
128133
def pool(self) -> libzfs.ZFSPool:
129134
return self.zfs.get_pool(self.dataset_name)
@@ -321,6 +326,9 @@ def __init__(
321326
logger=logger
322327
)
323328

329+
def destroy(self):
330+
raise NotImplementedError("destroy unimplemented for DefaultResource")
331+
324332
def save(self) -> None:
325333
self.write_config(self.config.user_data)
326334

@@ -349,6 +357,9 @@ def __init__(
349357

350358
self.filters = filters
351359

360+
def destroy(self):
361+
raise NotImplementedError("destroy unimplemented for ListableResource")
362+
352363
def __iter__(
353364
self
354365
) -> typing.Generator['iocage.lib.Resource.Resource', None, None]:

0 commit comments

Comments
 (0)