Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

Make ScoreRequest JSON serialiazble#271

Merged
adamwight merged 2 commits intomasterfrom
T206334
Oct 11, 2018
Merged

Make ScoreRequest JSON serialiazble#271
adamwight merged 2 commits intomasterfrom
T206334

Conversation

@Ladsgroup
Copy link
Copy Markdown
Member

Bug: T206334

Bug: T206334
Change-Id: I5c0122f7c1765a41fa172e2a073def7b54720f79
@Ladsgroup
Copy link
Copy Markdown
Member Author

I tested on all ways possible and it worked just fine.

Copy link
Copy Markdown
Contributor

@adamwight adamwight left a comment

Choose a reason for hiding this comment

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

I'm fine with merging as-is, but had one cleanup question.

Comment thread ores/score_request.py Outdated
"ip={0!r}".format(self.ip),
"model_info={0!r}".format(self.model_info)]))

def toJSON(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think "JSON" is the right word for what we're doing here. Technically, it's "marshalling" although that doesn't exactly roll off the tongue. Also, Python breaks the term by misusing it as another name for serialization.

What do you think about "toData" and "newFromData"?

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.

Can you say more why you don't think "JSON" is the right term? Maybe you mean "JSONable" since it's not turning the data structure into JSON, but rather a trivially JSON-able python data structure.

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.

Oh also the name is a style issue. Should probably be "to_json" or something like that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Renamed them to to_json and from_json

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I renamed it to to_json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Exactly, I was recommending against to_json because it doesn't create JSON. It's technically https://en.wikipedia.org/wiki/Marshalling_(computer_science) which is not serialization, we could pickle this data structure and so on.

This isn't a blocker though.

Comment thread ores/score_request.py
'model_info': self.model_info
}

@classmethod
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice use of classmethod :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Got it from pywikibot 🙈🙈

Comment thread ores/score_request.py Outdated
kwargs['context'],
kwargs['rev_ids'],
kwargs['model_names'],
precache=kwargs.get('precache', False),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Curious why there are defaults here. It doesn't seem like the fields are optional in our serialized format, at least.

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.

Indeed. Why not just do cls(**kwargs)?

Also, I think this is a confusing use of "kwargs" since it generally refers to key word arguments, but here, you are taking a deserialized JSON document.

Comment thread ores/score_request.py Outdated
}

@classmethod
def fromJSON(cls, kwargs):
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.

should probably be "from_json"

Change-Id: I9db4baefab36df6cc170432246b5a613b4dd38ab
@adamwight adamwight merged commit 640629b into master Oct 11, 2018
@adamwight adamwight deleted the T206334 branch October 11, 2018 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants