Support type designators that are also key slots#3
Open
gouttegd wants to merge 2 commits into
Open
Conversation
A type designator slot may also be the key (or even the identifier) slot
if its class. Combined with dict inlining, this can be used to do
something like this:
items:
FooItem:
# ... FooItem attributes
BarItem:
# ... BarItem attributes
BazItem:
# ... BazItem attributes
where FooItem, BarItem, and BazItem are all subclasses of Item (which is
the declared range of the `items` slot), and the keys of the `items`
dictionary act both as identifiers to refer to one particular item,
_and_ as type designators to indicate the precise type of each item (as
a side-effect, this ensures that `items` can only contain one object of
each type).
This is a pattern that could be useful for NGMF and/or NGFF extensions,
and that we should support.
This commit adds an explicit test case for it. The test currently
_fails_, because the ObjectConverter does not expect to find the type
designator as the key in a "inlined-as-dict" object.
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.
A type designator slot may also be the key (or even the identifier) slot if it's class. Combined with dict inlining, this can be used to do something like this:
where FooItem, BarItem, and BazItem are all subclasses of Item (which is the declared range of the
itemsslot), and the keys of theitemsdictionary act both as identifiers to refer to one particular item, and as type designators to indicate the precise type of each item (as a side-effect, this ensures thatitemscan only contain one object of each type).This is a pattern that could be useful for NGMF and/or NGFF extensions, and that we should support.
For now, this PR adds an explicit test case for it. The test currently fails, because the ObjectConverter does not expect to find the type designator as the key in a "inlined-as-dict" object.