From 979cd657059f61c7623529b0e9bac3e4e5384ac6 Mon Sep 17 00:00:00 2001 From: "philipp.thuerwaechter" Date: Wed, 18 Jul 2012 10:34:41 +0200 Subject: [PATCH] Allow use of 'None' as 'missing' for Numbers. --- colander/__init__.py | 2 +- colander/tests/test_colander.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/colander/__init__.py b/colander/__init__.py index c1e92aeb..260db5e1 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -951,7 +951,7 @@ class Number(SchemaType): num = None def serialize(self, node, appstruct): - if appstruct is null: + if not appstruct: return null try: diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index eb13f385..05f986c5 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -1148,6 +1148,14 @@ def test_serialize_null(self): result = typ.serialize(node, val) self.assertEqual(result, colander.null) + def test_serialize_none(self): + import colander + val = None + node = DummySchemaNode(None) + typ = self._makeOne() + result = typ.serialize(node, val) + self.assertEqual(result, colander.null) + def test_serialize_emptystring(self): import colander val = ''