only treat the first arg as typ if it is not a schema node
This commit is contained in:
@@ -1908,15 +1908,14 @@ class _SchemaNode(object):
|
|||||||
return node
|
return node
|
||||||
|
|
||||||
def __init__(self, *arg, **kw):
|
def __init__(self, *arg, **kw):
|
||||||
# bw compat forces us to treat first arg as type always
|
# bw compat forces us to treat first arg as type if not a _SchemaNode
|
||||||
if 'typ' in kw:
|
if 'typ' in kw:
|
||||||
self.typ = kw.pop('typ')
|
self.typ = kw.pop('typ')
|
||||||
_add_node_children(self, arg)
|
elif arg and not isinstance(arg[0], _SchemaNode):
|
||||||
elif arg:
|
self.typ, arg = arg[0], arg[1:]
|
||||||
self.typ = arg[0]
|
|
||||||
_add_node_children(self, arg[1:])
|
|
||||||
else:
|
else:
|
||||||
self.typ = self.schema_type()
|
self.typ = self.schema_type()
|
||||||
|
_add_node_children(self, arg)
|
||||||
|
|
||||||
# bw compat forces us to manufacture a title if one is not supplied
|
# bw compat forces us to manufacture a title if one is not supplied
|
||||||
title = kw.get('title', self.title)
|
title = kw.get('title', self.title)
|
||||||
@@ -2218,22 +2217,16 @@ SchemaNode = _SchemaMeta(
|
|||||||
class Schema(SchemaNode):
|
class Schema(SchemaNode):
|
||||||
schema_type = Mapping
|
schema_type = Mapping
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
|
||||||
SchemaNode.__init__(self, Mapping(), *args, **kw)
|
|
||||||
|
|
||||||
MappingSchema = Schema
|
MappingSchema = Schema
|
||||||
|
|
||||||
class TupleSchema(SchemaNode):
|
class TupleSchema(SchemaNode):
|
||||||
schema_type = Tuple
|
schema_type = Tuple
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
|
||||||
SchemaNode.__init__(self, Tuple(), *args, **kw)
|
|
||||||
|
|
||||||
class SequenceSchema(SchemaNode):
|
class SequenceSchema(SchemaNode):
|
||||||
schema_type = Sequence
|
schema_type = Sequence
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
SchemaNode.__init__(self, Sequence(), *args, **kw)
|
SchemaNode.__init__(self, *args, **kw)
|
||||||
if len(self.children) != 1:
|
if len(self.children) != 1:
|
||||||
raise Invalid(self,
|
raise Invalid(self,
|
||||||
'Sequence schemas must have exactly one child node')
|
'Sequence schemas must have exactly one child node')
|
||||||
|
Reference in New Issue
Block a user