Skip to content

Python parameters: fix as_dict() methods for correct serialization#8

Merged
ax3l merged 1 commit into
ax3l:topic-lwfaGUIcfgfrom
codingS3b:topic-lwfaGUIcfg
Nov 1, 2017
Merged

Python parameters: fix as_dict() methods for correct serialization#8
ax3l merged 1 commit into
ax3l:topic-lwfaGUIcfgfrom
codingS3b:topic-lwfaGUIcfg

Conversation

@codingS3b
Copy link
Copy Markdown

Refactor the as_dict() method for both Parameter and UiParameter class.
They now no longer use the __dict__ method since this returns a reference to the members of the objects and by deleting from this dictionary, one effectively removes member-variables from objects.
Instead dictionary creation is done manually.
Now serialization data also includes the lambda for formatting, the label, the class of an object and the dtype as a string.

del members["formatter"]
del members["dtype"]
members["label"] = self.label
members["formatter"] = str(inspect.getsourcelines(self.formatter)[
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

did you try this with multi-line formatters?

Copy link
Copy Markdown
Author

@codingS3b codingS3b Nov 1, 2017

Choose a reason for hiding this comment

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

No, I haven't done so yet...
For multiline functions one would need to do it a little differently, see e.g. the example here
https://stackoverflow.com/a/30984045

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

we should add that to avoid bad side effects if users do not pass a one-line lambda

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Then maybe we could use something like this:

members["formatter"] = ' '.join(inspect.getsourcelines(self.formatter)[0]).strip()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

but how to de-serialize it again to clean multi-lines?

@ax3l ax3l merged commit 886addf into ax3l:topic-lwfaGUIcfg Nov 1, 2017
ax3l pushed a commit that referenced this pull request Nov 3, 2017
8a0e21bea Merge pull request #13 from ComputationalRadiationPhysics/topic-wextra
65b082e27 Fix Unused Parameter Warning
5888a7a63 Travis: Werror
34d6e74bc Merge pull request #12 from psychocoderHPC/fix-warningUnusedReturnValue
9d49d4a6d fix warning `result of call is not use`
c9fa12e90 Merge pull request #8 from ComputationalRadiationPhysics/topic-cincludes
62e29c061 Includes: C includes in C++

git-subtree-dir: thirdParty/cuda_memtest
git-subtree-split: 8a0e21bea7be98a1d0f0f9fc48ae90f87c3ecb81
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.

2 participants