Skip to content
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

SYNPY-795 & SYNPY-797 #577

Merged
merged 3 commits into from Aug 16, 2018
Merged

SYNPY-795 & SYNPY-797 #577

merged 3 commits into from Aug 16, 2018

Conversation

kimyen
Copy link
Contributor

@kimyen kimyen commented Aug 16, 2018

No description provided.

@@ -861,6 +864,10 @@ def __init__(self, id=None, columnType=None, name=None):
def from_column(cls, column):
return cls(column.get('id', None), column.get('columnType', None), column.get('name', None))

@classmethod
def from_data(cls, data):
Copy link
Contributor

Choose a reason for hiding this comment

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

from_dict would make it more clear that the expected arguments are dicts

@@ -1075,6 +1085,10 @@ def __init__(self, values, rowId=None, versionNumber=None, etag=None):
if etag is not None:
self.etag = etag

@classmethod
def from_data(cls, data):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer **kwargs to be present in the constructor for this method because Rows are sent back and forth between the client and backend. kwargs would need to be documented to indicate that they are used only for unexpected fields introduced in newer versions of the backend. Using kwargs with self.update(kwargs) ensures that all of the fields are saved within the scope of the class instance's constructor. The alternative is to do:

@classmethod
def from_data(cls, data):
    copy_dict = dict(data)
    inst = cls(copy_dict .pop('values'), copy_dict .pop('rowId', None), copy_dict .pop('versionNumber', None), copy_dict .pop('etag', None))
    inst.update(copy_data)
    return inst

This is not only messier stylistically but it also tags on unexpected fields (from newer versions of the JSON object) into an already partially instantiated object. It would not be clear to someone just reading the constructor that unexpected fields are allowed/exist.

@zimingd zimingd merged commit e816afb into Sage-Bionetworks:develop Aug 16, 2018
@kimyen kimyen deleted the SYNPY-795 branch September 6, 2018 00:07
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.

None yet

2 participants