-
Notifications
You must be signed in to change notification settings - Fork 5
fix: Use Python object for Score, handle descriptor correctly, do not copy parent fields #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Use Python object for Score, handle descriptor correctly, do not copy parent fields #66
Conversation
… copy parent fields - Using Python object for Score allows Python libraries to interpret the score, allowing the @planning_solution class, justification and other Python classes that has a score to be used by Pydantic and the like. This also allows `Score | None` to be used in type annotations. - Handle descriptors correctly. Previously, instance fields were generated for them (which is incorrect, since they are functions to be called by __getattribute__). Now, the static attributes of a Python class are checked, and all static attributes that are descriptors are removed from the instance field candidate set. This uses an API that was added in Python 3.11 (inspect.getmembers_static). We do a best attempt in Python 3.10 to resolve descriptor correctly. This causes test failures for Python 3.10 in jpyinterpreter but not for timefold.solver. Tests in Python 3.11 and above all pass. - Previously, parent fields were sometimes added to the instance field candidate set, causing some fields to incorrectly be None when unwrapping a PythonLikeObject. Now, all parent fields are removed from the instance field candidate set. - Made toString() call $method$__str__(), and change the return type of $method$__str__() to PythonString so overrides work correctly.
- Note: Python Software Foundation License is similar to the Apache license; https://www.apache.org/legal/resolved.html#category-a
|
There are some nice Java tests validating the conversion between Python and Java objects. However, I couldn't find any Python code using or testing the new score structure. I recommend adding some domain/tests using medium and bendable scores.
There are some new tests, but I'm not entirely sure they cover all the behavior added by this change. Am I wrong?
I noticed that you didn't update all Python types, such as 'PythonLikeList'. Is there any specific reason for that? If not, please double-check to ensure all the required types are updated. |
That because all the existing tests (which previously uses the Java score) uses the Python score and weren't change
The Score python classes cover this behaviour.
Generally speaking, only the Python type that overridden |
Okay, I still believe that creating Python classes using the new structure is a good idea, similar to what we did in
That means the non-updated types will continue using the "incorrect" logic. In this case, we should keep the new logic consistent across all types. |
No, the logic for things without |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new score classes and the updated internal behavior are significant improvements!
Using Python object for Score allows Python libraries to interpret the
score, allowing the
@planning_solution
class, justification andother Python classes that has a score to be used by Pydantic and
the like. This also allows
Score | None
to be used in typeannotations.
Handle descriptors correctly. Previously, instance fields were
generated for them (which is incorrect, since they are functions
to be called by
__getattribute__
). Now, the static attributesof a Python class are checked, and all static attributes that
are descriptors are removed from the instance field candidate
set. This uses an API that was added in Python 3.11
(inspect.getmembers_static). For Python 3.10, we copied the
inspect.getmembers_static
code.Previously, parent fields were sometimes added to the instance
field candidate set, causing some fields to incorrectly be None
when unwrapping a
PythonLikeObject
. Now, all parent fields areremoved from the instance field candidate set.
Made
toString()
call$method$__str__()
, and change the returntype of
$method$__str__()
toPythonString
so overrides workcorrectly.