From c8f6057e7c5bc3e7b33c584c932fa8dd48fc29b3 Mon Sep 17 00:00:00 2001 From: PrasanthChettri Date: Tue, 18 May 2021 11:12:16 +0530 Subject: [PATCH] added None as default argument for exclude --- sqlalchemy_mixins/serialize.py | 8 ++++---- sqlalchemy_mixins/serialize.pyi | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sqlalchemy_mixins/serialize.py b/sqlalchemy_mixins/serialize.py index a8f2e93..7df8b6c 100644 --- a/sqlalchemy_mixins/serialize.py +++ b/sqlalchemy_mixins/serialize.py @@ -8,7 +8,7 @@ class SerializeMixin(InspectionMixin): __abstract__ = True - def to_dict(self,nested =False, hybrid_attributes=False, exclude = []): + def to_dict(self,nested = False, hybrid_attributes = False, exclude = None): """Return dict object with model's data. :param nested: flag to return nested relationships' data if true @@ -18,10 +18,10 @@ def to_dict(self,nested =False, hybrid_attributes=False, exclude = []): """ result = dict() - if len(exclude) != 0 : - view_cols = filter(lambda e: e not in exclude, self.columns) - else : + if exclude is None: view_cols = self.columns + else : + view_cols = filter(lambda e: e not in exclude, self.columns) for key in view_cols : result[key] = getattr(self, key) diff --git a/sqlalchemy_mixins/serialize.pyi b/sqlalchemy_mixins/serialize.pyi index ead75b3..df9d3a6 100644 --- a/sqlalchemy_mixins/serialize.pyi +++ b/sqlalchemy_mixins/serialize.pyi @@ -1,6 +1,6 @@ from sqlalchemy_mixins.inspection import InspectionMixin - +from typing import Optional , List class SerializeMixin(InspectionMixin): - def to_dict(self, nested: bool = False, hybrid_attributes: bool = False) -> dict: ... \ No newline at end of file + def to_dict(self, nested: bool = False, hybrid_attributes: bool = False, exclude: Optional[List[str]] = None) -> dict: ...