From 24f648dd14191dd348146267793d686792c63f8e Mon Sep 17 00:00:00 2001 From: Daniel Nouri Date: Wed, 15 Aug 2012 13:18:38 +0200 Subject: [PATCH] Allow the use of 'missing=None' for Number --- CHANGES.txt | 6 ++++++ colander/__init__.py | 2 +- colander/tests/test_colander.py | 7 +++++++ setup.py | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index da671352..5ff7ec70 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,12 @@ Changes ======= +Next release +------------ + +- Allow the use of 'missing=None' for Number. See + https://github.com/Pylons/colander/pull/59 . + 0.9.8 (2012-04-27) ------------------ diff --git a/colander/__init__.py b/colander/__init__.py index 260db5e1..a37b2730 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -951,7 +951,7 @@ class Number(SchemaType): num = None def serialize(self, node, appstruct): - if not appstruct: + if appstruct in (null, None): return null try: diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index 05f986c5..229c97f0 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -1192,6 +1192,13 @@ def test_serialize_ok(self): result = typ.serialize(node, val) self.assertEqual(result, '1') + def test_serialize_zero(self): + val = 0 + node = DummySchemaNode(None) + typ = self._makeOne() + result = typ.serialize(node, val) + self.assertEqual(result, '0') + class TestFloat(unittest.TestCase): def _makeOne(self): from colander import Float diff --git a/setup.py b/setup.py index c75ef492..42b643b7 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ docs_extras = ['Sphinx'] setup(name='colander', - version='0.9.8', + version='0.9.9dev1', description=('A simple schema-based serialization and deserialization ' 'library'), long_description=README + '\n\n' + CHANGES,