On Wed, Jun 10, 2015 at 11:41:27AM +0200, Adnan Yaqub wrote:
>    Hi.
>    I am using generateDS-2.15a-py2.7 and when I try to parse an XSD I am
>    getting the error "UnboundLocalError: local variable 'element'
>    referenced before assignment".

[snip]

>    The code in question appears to be:
>            elif (name == ElementType or
>                    (name == ComplexTypeType and
>    self.stack[-1].complexType)):
>                self.inElement = 0
>                self.inNonanonymousComplexType = 0
>                if len(self.stack) >= 2:
>                    element = self.stack.pop()
>                    self.stack[-1].addChild(element)
>                if name == ElementType and len(self.stack) == 1:
>                    element.setIsRootElement(True)
>                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    Is there a fix for this?
>    Thanks,

Adnan,

I apologize for being slow.  I just returned from a trip to
north-west California, in Crescent City, Calif, USA and the ocean
beaches and redwood forests that are nearby.  We saw huge,
incredibly tall redwood trees in the old-growth forest.  And, we had
enjoyable walks on lovely trails with a large variety of ferns and
other plants and flowers along the trails.  Also, I was thrilled to
see a Pacific Loon: the first time I've seen a bird of this species.

Back to work ...

I have not been able to reproduce this error.  It seems to me that
the undefined variable (element) should have been set 3 line above
the line where the exception happened.

I've attached a patch.  I believe it protects us from that
exception.  But, since I do not know how to reproduce the error, I'm
not sure.

Is the XML schema that used when you produced this error something
that you can share with me?  It would help if you can send me either
that schema (and any schema files that it imports) or a minimal
schema that produces the error.

Also, could you please send the command line (and command line
options) that you used when the error occurred.

Thanks for help.

Dave


-- 

Dave Kuhlman
http://www.davekuhlman.org
diff -r be611f0a9d41 generateDS.py
--- a/generateDS.py     Fri May 29 13:26:17 2015 -0700
+++ b/generateDS.py     Mon Jun 15 14:17:42 2015 -0700
@@ -1708,10 +1708,13 @@
                 (name == ComplexTypeType and self.stack[-1].complexType)):
             self.inElement = 0
             self.inNonanonymousComplexType = 0
+            element = None
             if len(self.stack) >= 2:
                 element = self.stack.pop()
                 self.stack[-1].addChild(element)
-            if name == ElementType and len(self.stack) == 1:
+            if (name == ElementType and
+                    len(self.stack) == 1
+                    and element is not None):
                 element.setIsRootElement(True)
         elif name == AnyType:
             if len(self.stack) >= 2:
------------------------------------------------------------------------------
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to