Skip to content

Support type designators that are also key slots#3

Open
gouttegd wants to merge 2 commits into
mainfrom
type-designator-as-key
Open

Support type designators that are also key slots#3
gouttegd wants to merge 2 commits into
mainfrom
type-designator-as-key

Conversation

@gouttegd

Copy link
Copy Markdown
Owner

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:

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.

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.

gouttegd added 2 commits June 26, 2026 15:29
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.
@gouttegd gouttegd self-assigned this Jun 26, 2026
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.

1 participant