@@ -850,7 +850,10 @@ def visit_sequence(self, node, parent):
850850
851851 annotation , items = self ._pop_annotation (node .getchildren ())
852852 for child in items :
853- assert child .tag in sub_types , child
853+ if child .tag not in sub_types :
854+ raise self ._create_error (
855+ "Unexpected element %s in xsd:sequence" % child .tag , child )
856+
854857 item = self .process (child , node )
855858 assert item is not None
856859 result .append (item )
@@ -1166,12 +1169,16 @@ def _process_attributes(self, node, items):
11661169 attribute = self .process (child , node )
11671170 attributes .append (attribute )
11681171 else :
1169- raise XMLParseError (
1170- "Unexpected tag `%s`" % (child .tag ),
1171- filename = self .document ._location ,
1172- sourceline = node .sourceline )
1172+ raise self ._create_error (
1173+ "Unexpected tag `%s`" % (child .tag ), node )
11731174 return attributes
11741175
1176+ def _create_error (self , message , node ):
1177+ return XMLParseError (
1178+ message ,
1179+ filename = self .document ._location ,
1180+ sourceline = node .sourceline )
1181+
11751182 visitors = {
11761183 tags .any : visit_any ,
11771184 tags .element : visit_element ,
0 commit comments