-
-
Notifications
You must be signed in to change notification settings - Fork 411
Rewrite MPS parsing to use dataclasses instead of dicts #831
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
Conversation
how to you feel about using TypedDicts instead of dataclasses? This way we keep dictionaries and still have type checking without needing extra dependencies. |
I think dataclasses are the better approach. Three other options:
|
Understood. Let's just add the |
I'm taking a look at how much extra code it might be to implement converting dicts to a dataclass: @dataclass
class MPSParameters:
name: str
sense: int
status: int
sol_status: int
@classmethod
def fromDict(cls, data: dict[str, Any]) -> MPSParameters:
return cls(data["name"], data["sense"], data["status"], data["sol_status"]) Each of the MPS dataclasses will just need to manually parse the dict. |
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 for this, it's looking very good. I see that you added some from_dict
and fromDict
to cover the previous methods in some cases. But I think that many classes have lost them. Can you check and add the (now useless) fromDict
, from_dict
, toDict
and to_dict
. Ideally, with some kind of deprecation warning? So that we can take them out in a next version.
For example, LpVariable
is missing from_dict
and fromDict
methods. LpProblem
is missing to_dict
and from_dict
.
Others are missing more.
I hate to being picky about this but I already had issues removing an undocumented alias I had for a method and someone, somewhere came back to complain I did not add a deprecation warning before removing it.
@classmethod | ||
def fromDict(cls, dj=None, varValue=None, **kwargs): |
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.
I think we're missing the fromDict methods somewhere. Just for deprecation reasons, even if they're not useful anymore in pulp.
Do you want all |
I think the Thanks again. |
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.
a typo in a warning. Besides that I think it's ready to merge. Right?
pulp/pulp.py
Outdated
:rtype: list | ||
""" | ||
warnings.warn( | ||
"LpAffineExpression.to_dict is deprecated, use LpAffineExpression.toDataclass instead", |
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.
I think here it should say: "... use LpAffineExpression.toDict instead"
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.
Fixed.
Yes, I think all good to merge. |
In the spirit of breaking out changes from #807, this PR includes rewriting parsing MPS files to use dataclasses instead of dicts.
This change does not add any new capabilities, and was done to:
As raised in #807, a downside is that this adds a dependency on dacite, whereas there were not previously any (depending on which backend is in use).