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

Bugfix/handle default fields #96

Merged
merged 4 commits into from
Dec 12, 2021
Merged

Bugfix/handle default fields #96

merged 4 commits into from
Dec 12, 2021

Conversation

FabienRoger
Copy link
Contributor

Add default fields to edges, sockets, blocks, code blocks and scenes.
Resolves issue #95 for most practical purposes.

@FabienRoger FabienRoger linked an issue Dec 6, 2021 that may be closed by this pull request
Copy link
Member

@MathisFederico MathisFederico left a comment

Choose a reason for hiding this comment

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

Refactor using no unnecessary constants

opencodeblocks/blocks/block.py Show resolved Hide resolved
Comment on lines +336 to +344
def complete_with_default(self, data: OrderedDict) -> None:
"""Add default data in place when fields are missing"""
for key in NONE_OPTIONAL_FIELDS:
if key not in data:
raise ValueError(f"{key} of the socket is missing")

for key in DEFAULT_BLOCK_DATA:
if key not in data:
data[key] = DEFAULT_BLOCK_DATA[key]
Copy link
Member

Choose a reason for hiding this comment

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

Using global constants lead to a triple duplicate of this same code, a good example of why constants should be use with care !

Copy link
Member

Choose a reason for hiding this comment

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

I still feel like this is a duplicate, am I missing something ?

Copy link
Member

@MathisFederico MathisFederico left a comment

Choose a reason for hiding this comment

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

I don't get it, doesn't the Serializable refactor clear the need of this branch anyway ?

opencodeblocks/blocks/block.py Show resolved Hide resolved
Comment on lines +336 to +344
def complete_with_default(self, data: OrderedDict) -> None:
"""Add default data in place when fields are missing"""
for key in NONE_OPTIONAL_FIELDS:
if key not in data:
raise ValueError(f"{key} of the socket is missing")

for key in DEFAULT_BLOCK_DATA:
if key not in data:
data[key] = DEFAULT_BLOCK_DATA[key]
Copy link
Member

Choose a reason for hiding this comment

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

I still feel like this is a duplicate, am I missing something ?

@vanyle vanyle merged commit e233ae3 into master Dec 12, 2021
@MathisFederico MathisFederico deleted the bugfix/handle_default_fields branch December 14, 2021 13:28
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.

Serialized object don't have default fields
3 participants