- Raise a `TypeError` when bogus keyword arguments are passed to

``colander.SchemaNode``.
This commit is contained in:
Chris McDonough
2010-05-27 08:54:34 +00:00
parent 3655ee98cb
commit 2bc84d1431
3 changed files with 13 additions and 5 deletions

View File

@@ -14,6 +14,9 @@ Next release
Positional. This attribute isn't an API; it's used only internally
for reporting.
- Raise a ``TypeError`` when bogus keyword arguments are passed to
``colander.SchemaNode``.
0.6.2 (2010-05-08)
------------------

View File

@@ -1112,11 +1112,13 @@ class SchemaNode(object):
def __init__(self, typ, *children, **kw):
self.typ = typ
self.validator = kw.get('validator', None)
self.default = kw.get('default', _missing)
self.name = kw.get('name', '')
self.title = kw.get('title', self.name.capitalize())
self.description = kw.get('description', '')
self.validator = kw.pop('validator', None)
self.default = kw.pop('default', _missing)
self.name = kw.pop('name', '')
self.title = kw.pop('title', self.name.capitalize())
self.description = kw.pop('description', '')
if kw:
raise TypeError('Unknown keyword arguments: %s' % repr(kw))
self.children = list(children)
def __repr__(self):

View File

@@ -1281,6 +1281,9 @@ class TestSchemaNode(unittest.TestCase):
self.assertEqual(node.name, 'name')
self.assertEqual(node.title, 'Name')
def test_ctor_with_bad_kwarg(self):
self.assertRaises(TypeError, self._makeOne, None, 0, foo=1)
def test_ctor_with_title(self):
node = self._makeOne(None, 0, validator=1, default=2, name='name',
title='title')