Python parameters: fix as_dict() methods for correct serialization#8
Merged
Merged
Conversation
ax3l
reviewed
Nov 1, 2017
| del members["formatter"] | ||
| del members["dtype"] | ||
| members["label"] = self.label | ||
| members["formatter"] = str(inspect.getsourcelines(self.formatter)[ |
Owner
There was a problem hiding this comment.
did you try this with multi-line formatters?
Author
There was a problem hiding this comment.
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
Owner
There was a problem hiding this comment.
we should add that to avoid bad side effects if users do not pass a one-line lambda
Author
There was a problem hiding this comment.
Then maybe we could use something like this:
members["formatter"] = ' '.join(inspect.getsourcelines(self.formatter)[0]).strip()
Owner
There was a problem hiding this comment.
but how to de-serialize it again to clean multi-lines?
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor the
as_dict()method for bothParameterandUiParameterclass.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.