Added a dict wrapper that acts like an object #1824
Merged
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.
@Nick-Hall had an interesting idea to make the raw dict from JSON act like an object. In that way, instead of writing:
you could write:
And if you rename
data
toperson
it looks like regular gramps for all of the attributes of all of the Gramps objects:This has all of the benefits of quick access (no object creation) with a convenient syntax.
However that could create some confusion because methods can't be called as it isn't a real
Person
. With a couple of additional lines, it can act as a real object:This allows us to use the full object attribute and methods, only creating an object when necessary. Sometimes it is necessary, such as:
(Although this only instantiates a PersonRef(), much cheaper than instantiating the whole Person)
With this PR applied, I found that
person.get_gender()
was 4.4 times slower thanperson.gender
. The only downside with this PR is that those writing code (filter rules, for example) might not realize that they are creating an object when it is not necessary.