forked from ax3l/pydantic-mad
-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Implementation of the name based listing #12
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e745e83
Implementation of the name based listing https://github.com/campa-con…
danielkallendorf ccb3c51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b57d58a
Updated unit tests
danielkallendorf 277cf21
Merge branch 'main' of https://github.com/danielkallendorf/pals-python
danielkallendorf 95783a9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the idea of the PR, but I just noticed an issue with the data structure:
I think it does not work to make
Linean ordered dict, or a dictionary at all.The problem with dictionaries is that their elements are either unsorted (generally random, i.e. independent of name and insertion order because they are usually implemented as hash tables, where a key is hashed to determine which "bucket" an element belongs in) or sorted, by (key) name in our case, which is not what we want for a beamline/segment: we need a datastructure that strictly keeps the insertions order (across programming languages and formats). That format is a list.
As a specialty of Python, since 3.7 Python dicts preserve the insertation order, but that is not very portable to assume for other programming languages (or even YAML libraries).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what works is this:
that then looks in Python like this:
and in a Python API it stays as now:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for completeness, one cannot really do:
which represents
because then the random key that is the name is unclear how to pick out (again: order is not guaranteed, it might not be first)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ax3l
In your comment above, #12 (comment), did you have in mind that
linewould be a list of dict, so something likeor did you have in mind that we should implement some sort of new
WrapperElementclass (also derived fromBaseModel, like all other element classes) that has a single attribute, a dictionary, which is the initialized to store one single "key: value" pair, where the value is the original dictionary of properties obtained by a model_dump from the a given element?I have experimented a bit with the latter but it does not seem very easy to me. It also seems to require custom serialization and deserialization, which makes me think that we could do just that (custom serialization and deserialization, as done in #8) without the layer of the dictionary wrapper.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, line as a list of dict :)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(with references to other pre-defined elements, it will then be a
list of dict|str, but we can add references and inheritance of elements in a follow-up. Thedictpart or its attributes we could still derive from a base element.)