matthiaskoenig / sbmlutils

Python utilities for SBML
https://sbmlutils.readthedocs.io/en/stable/
GNU Lesser General Public License v3.0
37 stars 12 forks source link

Parser formula definition uses `ast` before assignment. #443

Closed castagninojose closed 2 months ago

castagninojose commented 3 months ago

Problem description

Please explain:

Code Sample

Create a minimal, complete, verifiable example.

from sbmlutils import parser
parser.sbml_to_model("iec1368_dh5a.sbml")

Context

I was able to get around the issue by simply adding a new else condition @parser.py (L248), going from this:

        if r.isSetKineticLaw():
            klaw: libsbml.KineticLaw = r.getKineticLaw()
            if klaw.isSetMath():
                ast = klaw.getMath()
            else:
                ast = None

        formula = libsbml.formulaToL3String(ast) if ast else None

To this

        if r.isSetKineticLaw():
            klaw: libsbml.KineticLaw = r.getKineticLaw()
            if klaw.isSetMath():
                ast = klaw.getMath()
            else:
                ast = None
        else:
            ast = None

        formula = libsbml.formulaToL3String(ast) if ast else None

I'm not at all familiar with the inner workings of this library but it seems that the first conditional is not met and so ast is never assigned to anything.

I searched for other issues in this repository but could not find anything. If this is a misuse on my end or an already contemplated/documented case feel free to close.

matthiaskoenig commented 2 months ago

Thanks for the report and sorry for the slow reply. This will be addressed in the next release.