我不知道如何使用用户定义的函数作为Eisbach方法代码的一部分来评估术语,也不知道如何与术语匹配。以下是Coq Ltac的(简化)定义,我想将其作为Isabelle / HOL中的Eisbach方法编写:
class CustomSerializer(Serializer):
def end_object(self, obj):
for field in self.selected_fields:
if field in self._current.keys():
continue
else:
if field.find('__') > -1:
try:
fks = field.split('__')
curr_value = obj
while(len(fks)>0):
current_key = fks.pop(0)
curr_value = getattr(curr_value, current_key)
self._current[field] = curr_value
except AttributeError:
pass
super(CustomSerializer, self).end_object(obj)
# usage
data = CustomSerializer().serialize(
Comment.objects.all(),
fields = (
'pk',
# other fields in Comment Object
'author__username' # it belongs to Author Model
)