From ab79b26bec4fe673595b15a125404057c145f3d8 Mon Sep 17 00:00:00 2001 From: Tom Samstag Date: Mon, 9 May 2016 23:10:52 -0700 Subject: [PATCH] make EditPrimary, empty_object abstract This makes EditPrimary an abstract class using abc.ABCMeta and marks EditPrimary.empty_object as an abstract method. This moves the error raised by forgetting to implement empty_object from when something unsupported is done with its return (like .serialize()) to invocation time, and provides a more obvious error. --- gramps/gui/editors/editprimary.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gramps/gui/editors/editprimary.py b/gramps/gui/editors/editprimary.py index ee6b4efe1..9a7acc75c 100644 --- a/gramps/gui/editors/editprimary.py +++ b/gramps/gui/editors/editprimary.py @@ -26,6 +26,7 @@ #------------------------------------------------------------------------- from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext +import abc #------------------------------------------------------------------------- # @@ -49,7 +50,7 @@ from ..dialog import SaveDialog from gramps.gen.lib import PrimaryObject from ..dbguielement import DbGUIElement -class EditPrimary(ManagedWindow, DbGUIElement): +class EditPrimary(ManagedWindow, DbGUIElement, metaclass=abc.ABCMeta): QR_CATEGORY = -1 @@ -245,12 +246,9 @@ class EditPrimary(ManagedWindow, DbGUIElement): self._do_close() return False + @abc.abstractmethod def empty_object(self): - #empty_object should be overridden in base class and will throw an - #exception if it is not because self.empty_object().serialize() is - #called and PrimaryObject does not implement serialize(). See - #BaseObject.serialize() - return PrimaryObject + """ empty_object should be overridden in child class """ def data_has_changed(self): if self.db.readonly: