Menu

#23 Object has no attribute 'export'

1.0
open
Bug (1)
2021-10-01
2021-09-30
No

Hi Dave,

I used the latest version of generateDS (v2.40.1) and there seems to be a problem.
The generated code has __str__ method in the GeneratedsSuper class. This is new since the version 2.36.2
The problem is with the following:

    def __str__(self):
        ...
        from io import StringIO
        output = StringIO()
        self.export(
            output,
            settings['str_indent_level'],
            pretty_print=settings['str_pretty_print'],
            namespaceprefix_=settings['str_namespaceprefix'],
            name_=settings['str_name'],
            namespacedef_=settings['str_namespacedefs']
        )
        strval = output.getvalue()
        output.close()
        return strval

The self.export method does not exist because it is commented out. It gets commented out because in the template those lines are prefixed by #xmldisable# and we are using --disable-xml flag.

Discussion

  • Dave Kuhlman

    Dave Kuhlman - 2021-09-30

    Mustafa,

    Oops.

    OK, so I've "disabled" generation of that __str__ method. Actually, it's generated, but is commented out. That method is intended as a convenience for a programmer who wants to display an object while debugging. Am I right that you can do without it?

    With the new code and when using --disable-xml, when you ask for a string representation, you will see:

    [ins] In [21]: import tmp04sup as lib4
    [ins] In [22]: b = lib4.containerType()
    [ins] In [23]: print(str(b))
    <tmp04sup.containerType object at 0x7fd5b2651130>
    

    Attached is a patch file.

    I did some checking. But, I'm a little unsure about possible dependencies in that code. Could you try this patch and let me know. If all is well with it and you do not need that __str__ method, I'll create a new release.

    Dave

     
  • Mustafa Şenol Coşar

    Hi Dave, the patch works for me.

    Although having string representation could be nice. Something like the following when xml is not enabled:
    Class1(field1=value1, field2=value2, field3=Class2(field4=value4))

    However, it is not critical right now.

     
  • Dave Kuhlman

    Dave Kuhlman - 2021-10-01

    Mustafa,

    Uploaded the fix for __str__ and export with --disable-xml.

    It's version 2.40.2.

    Thanks for the help with this.

    Dave

     
  • Dave Kuhlman

    Dave Kuhlman - 2021-10-01

    Mustafa,

    I introduced a bug. I got the indentation of __str__ wrong.

    It is fixed in version 2.40.3.

    I apologize. Hope I got it right this time.

    I'll look into your suggestion for the improved __str__ method, next week.

    Dave

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.