Skip to content

Fix LicenseWithExceptionSymbol missing Expression class variables - #112

Merged
pombredanne merged 2 commits into
aboutcode-org:mainfrom
arbassett-qnx:patch-1
Apr 3, 2025
Merged

Fix LicenseWithExceptionSymbol missing Expression class variables#112
pombredanne merged 2 commits into
aboutcode-org:mainfrom
arbassett-qnx:patch-1

Conversation

@arbassett-qnx

Copy link
Copy Markdown

LicenseWithExceptionSymbol class AND,OR,Symbol variables coming from expression were not being set during init this causes issues when using python operators like and when the symbol is only LicenseWithExceptionSymbol

ex.

l1 = spdx_licensing.parse("GPL-3.0-or-later WITH GCC-exception-3.1")
l2 = spdx_licensing.parse("MIT")
l3 = l1 & l2

This will cause an exception as AND is NONE

Traceback (most recent call last):
  File "test.py", line 19, in <module>
    l3 = l1 & l2
         ~~~^~~~
  File ".venv/lib/python3.12/site-packages/boolean/boolean.py", line 864, in __and__
    return self.AND(self, other)
           ^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not callable

The fix is a copy of BooleanAlgebra init which does the same but for all types

Signed-off-by: Aaron Bassett <abassett@qnx.com>

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Do you mind to add a simple test too? And check if using a better super() call may resolve the issue too?

# FIXME: this should be instead a super class of all symbols
self.LicenseSymbol = self.Symbol
# LicenseWithExceptionSymbol does not get its internal Expressions mapped durring BooleanAlgebra init
# have to set it after the fact

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the solution could not be instead something about a better/different way to call super?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the better super call. originally that's what i was trying to do, but unless boolean is changed i don't think there is a way from what i can tell license-expression is a outlier with 2 symbol classes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah... Note that I maintain boolean too, so I could do it there, but that's indeed a weird thing, though may be the check should be for any symbol subclass somehow?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry i didn't realize you were also the maintainer of boolean.

Yea in boolean if you could do the same thing for all sub classes of the passed in symbol class that should fix it.

Is this something you would prefer to do if not i can take a look at it myself when i get the chance.

right now i'm working around it by just patching the operators right after the import using the same code

tf_nao = {
    "TRUE": spdx_licensing.TRUE,
    "FALSE": spdx_licensing.FALSE,
    "NOT": spdx_licensing.NOT,
    "AND": spdx_licensing.AND,
    "OR": spdx_licensing.OR,
    "Symbol": spdx_licensing.Symbol,
}

for name, value in tf_nao.items():
    setattr(LicenseWithExceptionSymbol, name, value)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some tests if the plan is to fix this in boolean should be a good base.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It looks like the boolean.py code will need a good facelift to account for this.

@arbassett-qnx

Copy link
Copy Markdown
Author

Good catch! Do you mind to add a simple test too? And check if using a better super() call may resolve the issue too?

Yea no problem ill add a test.

Signed-off-by: Aaron Bassett <abassett@qnx.com>

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks... just a tiny nit for your consideration.

# FIXME: this should be instead a super class of all symbols
self.LicenseSymbol = self.Symbol
# LicenseWithExceptionSymbol does not get its internal Expressions mapped durring BooleanAlgebra init
# have to set it after the fact

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It looks like the boolean.py code will need a good facelift to account for this.

Comment thread src/license_expression/__init__.py
@pombredanne
pombredanne merged commit afa6dce into aboutcode-org:main Apr 3, 2025
@arbassett-qnx
arbassett-qnx deleted the patch-1 branch April 3, 2025 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants