-
Notifications
You must be signed in to change notification settings - Fork 60
Fixed typing of arithmetic methods #454
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
Fixed typing of arithmetic methods #454
Conversation
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.
Thanks @RobbieKiwi, that was annoying. Could you also add the missing lines to the test and resolve the other mypy warnings?
Is there a reason why one of these should work and the other should give a type error? |
for more information, see https://pre-commit.ci
…m:RobbieKiwi/linopy into feature/variable_and_data_array_operators
@lkstrp I went down a bit of a rabbit hole with the typing in order to make sure the type checker could tell the difference between a LinearExpression and QuadraticExpression which involved breaking the inheritance between the two and making a base class. Could you please have another look? |
impressive work @RobbieKiwi ! @lkstrp or I will go through it soon! we'll make another release today but this will definitely go into the next one! |
for more information, see https://pre-commit.ci
…m:RobbieKiwi/linopy into feature/variable_and_data_array_operators
@RobbieKiwi do you remember why the merge function now requires a cls argument? I recon that it is a bit inconvenient for users... |
@FabianHofmann Now that LinearExpression and QuadraticExpression are separated this function would need some generic type matching to properly return the right type without mypy complaining. Expressing this just using the input expressions is impossible because of the complicated combination (LinearExpression + QuadraticExpression -> QuadraticExpression). Instead I opted for matching the type on the passed cls. The cls is still an optional parameter. If you don't pass it then you get mypy warnings in the CI pipeline and runtime warnings. |
thanks @RobbieKiwi ! that makes sense. atm we are just getting quite some deprecation warnings as we have not set the cls argument and I was wondering whether we couldn't do some sort of auto-detection like for example in |
Closes #435.
Changes proposed in this Pull Request
Arithmetic methods now understand that data array is a valid type for addition/multiplication
Checklist
doc
.doc/release_notes.rst
of the upcoming release is included.