Menu

#20 Using `--use-getter-setter=none` does not add `add_anytypeobjs_`, but this method is still used in places in the generated python

2.0
closed
nobody
None
2021-10-12
2021-08-27
Ankur Sinha
No

We've used --use-getter-setter=none to generate our Python file from the XSD. I see that this does not result in the definition of any add_anytypeobjs_() methods, but at the same time, there are lines that use this method: self.add_anytypeobjs_(content). This results in errors of the type "... has no method add_anytypeobjs_".

Should this method be used if it is not being declared?

$ grep -n "add_anytypeobjs" nml.py 
1218:        self.add_anytypeobjs_(content_)
8994:        self.add_anytypeobjs_(content_)
9341:        self.add_anytypeobjs_(content_)
12343:        self.add_anytypeobjs_(content_)
17312:        self.add_anytypeobjs_(content_)
17438:        self.add_anytypeobjs_(content_)

The xsd and related files are all attached.

5 Attachments

Discussion

  • Ankur  Sinha

    Ankur Sinha - 2021-08-27

    Here's an example error that we get while running our unit tests:

    'Annotation' object has no attribute 'add_anytypeobjs_'", AttributeError("'Annotation' object has no attribute 'add_anytypeobjs_'"))
    
     
  • Ankur  Sinha

    Ankur Sinha - 2021-08-27

    The attached tweaks in the generated nml.py file "fixes" this error.

     
  • Dave Kuhlman

    Dave Kuhlman - 2021-08-27

    I've made a fix to this. This patch will prevent the generation of the call to add_anytypeobjs_.

    diff -r 29824eaf0796 generateDS.py
    --- a/generateDS.py     Wed Aug 25 14:51:37 2021 -0700
    +++ b/generateDS.py     Fri Aug 27 16:22:15 2021 -0700
    @@ -4838,7 +4838,7 @@
                     wrt("        else:\n")
                 wrt("        %scontent_ = self.gds_build_any(child_, '%s')\n" % (
                     fill, type_name, ))
    -            wrt('        %sself.add_anytypeobjs_(content_)\n' % (fill, ))
    +            wrt('        %sself.anytypeobjs_.append(content_)\n' % (fill, ))
             else:
                 if keyword == 'if':
                     fill = ''
    

    Could you tell me what XML schema you are using that generates this error. That would enable me to test this change.

    Thanks.

    Dave

     
  • Ankur  Sinha

    Ankur Sinha - 2021-09-15

    Thanks very much, and sorry for the late reply.

    I've attached the XSD and other files we use for generation to the issue. You can also see them in our repository here:

    https://github.com/NeuralEnsemble/libNeuroML/tree/development/neuroml/nml

    The schema is currently at version 2.2

     
  • Dave Kuhlman

    Dave Kuhlman - 2021-09-15

    Ankur,

    I tried this with NeuroML_v2.2.xsd. See comments from generated module, below.

    I cannot find any references to add_anytypeobjs_. This was fixed in generateds v. 2.39.10, I believe.

    Let me know if generateds is still causing this problem.

    Dave

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    #
    # Generated Wed Sep 15 11:06:05 2021 by generateDS.py version 2.39.11.
    # Python 3.9.5 (default, May 11 2021, 08:20:37)  [GCC 10.3.0]
    #
    # Command line options:
    #   ('-f', '')
    #   ('-o', 'tmp02sup.py')
    #   ('-s', 'tmp02sub.py')
    #   ('--super', 'tmp02sup')
    #   ('--member-specs', 'dict')
    #   ('--export', 'write etree validate literal generator')
    #   ('--use-getter-setter', 'none')
    #
    # Command line arguments:
    #   libNeuroML/neuroml/nml/NeuroML_v2.2.xsd
    #
    # Command line:
    #   ./generateDS.py -f -o "tmp02sup.py" -s "tmp02sub.py" --super="tmp02sup" --member-specs="dict" --export="write etree validate literal generator" --use-getter-setter="none" libNeuroML/neuroml/nml/NeuroML_v2.2.xsd
    #
    # Current working directory (os.getcwd()):
    #   Test02
    #
    
     
  • Ankur  Sinha

    Ankur Sinha - 2021-10-12

    Thanks very much, Dave. I can confirm that this is now fixed. Please close this ticket as "fixed" :)

     
  • Dave Kuhlman

    Dave Kuhlman - 2021-10-12
    • status: open --> closed
     

Log in to post a comment.