- SchemaNode constructor now accepts arbitrary keyword arguments. It
sets any unknown values within the ``**kw`` sequence as attributes of the node object.
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
Changes
|
||||
=======
|
||||
|
||||
Unreleased
|
||||
----------
|
||||
0.9 (unreleased)
|
||||
-----------------
|
||||
|
||||
- SchemaNode constructor now accepts arbitrary keyword arguments. It
|
||||
sets any unknown values within the ``**kw`` sequence as attributes
|
||||
of the node object.
|
||||
|
||||
- Added Spanish locale: thanks to Douglas Cerna for the translations!
|
||||
|
||||
|
@@ -1207,8 +1207,7 @@ class SchemaNode(object):
|
||||
self.description = kw.pop('description', '')
|
||||
self.widget = kw.pop('widget', None)
|
||||
self.after_bind = kw.pop('after_bind', None)
|
||||
if kw:
|
||||
raise TypeError('Unknown keyword arguments: %s' % repr(kw))
|
||||
self.__dict__.update(kw)
|
||||
self.children = list(children)
|
||||
|
||||
@property
|
||||
|
@@ -1310,8 +1310,9 @@ class TestSchemaNode(unittest.TestCase):
|
||||
node = self._makeOne(None, 0, widget='abc')
|
||||
self.assertEqual(node.widget, 'abc')
|
||||
|
||||
def test_ctor_with_bad_kwargs(self):
|
||||
self.assertRaises(TypeError, self._makeOne, None, 0, foo=1)
|
||||
def test_ctor_with_unknown_kwarg(self):
|
||||
node = self._makeOne(None, 0, foo=1)
|
||||
self.assertEqual(node.foo, 1)
|
||||
|
||||
def test_required_true(self):
|
||||
node = self._makeOne(None)
|
||||
|
@@ -92,7 +92,9 @@ typically of the class :class:`colander.SchemaNode`, usually in a
|
||||
nested arrangement. Each schema node object has a required *type*, an
|
||||
optional deserialization *validator*, an optional *default*, an
|
||||
optional *missing*, an optional *title*, an optional *description*, an
|
||||
optional *widget*, and a slightly less optional *name*.
|
||||
optional *widget*, and a slightly less optional *name*. It also
|
||||
accepts *arbitrary* keyword arguments, which are attached directly as
|
||||
attributes to the node instance.
|
||||
|
||||
The *type* of a schema node indicates its data type (such as
|
||||
:class:`colander.Int` or :class:`colander.String`).
|
||||
@@ -130,6 +132,14 @@ be discussed any further in the Colander documentation; it will
|
||||
instead be explained in the context of the documentation of systems
|
||||
which make use of it.
|
||||
|
||||
Any other keyword arguments to a schema node constructor will be
|
||||
attached to the node unmolested (e.g. when ``foo=1`` is passed, the
|
||||
resulting schema node will have an attribute named ``foo`` with the
|
||||
value ``1``).
|
||||
|
||||
.. note:: Abitrary keyword arguments are allowed to a schema node
|
||||
constructor in Colander 0.9+. Prior version disallow them.
|
||||
|
||||
The name of a schema node that is introduced as a class-level
|
||||
attribute of a :class:`colander.MappingSchema`,
|
||||
:class:`colander.TupleSchema` or a :class:`colander.SequenceSchema` is
|
||||
|
Reference in New Issue
Block a user