Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 28, 2023
1 parent d1d5f08 commit 19f7b8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/roman_datamodels/datamodels/using_datamodels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ page::

There are a couple subtlties with regard to changing values in a datamodel.
If you assign dicts or lists to attributes, it will map these into the
corresponding DNode or LNode subclasses. In such uses, the assigned values
corresponding DNode or LNode subclasses. In such uses, the assigned values
will be immediately be checked by validating against the defining schemas.
When the value being assigned fails to pass that validation, an exception
will occur. This is generally a good thing, particularly if you are changing
values interactively

On the other hand, if one assigns to the attribute a subclass of DNode
or LNode, no immediate validation is done (for current implenentation
reasons). If the wrong kind of DNode or LNode is assigned to the
reasons). If the wrong kind of DNode or LNode is assigned to the
attribute that doesn't match the expected tag for that attribute, the error
will only be raised when trying to write the file to disk.

Expand Down
12 changes: 7 additions & 5 deletions src/roman_datamodels/stnode/_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""
from asdf.extension import Converter, ManifestExtension
from astropy.time import Time
from ._registry import (LIST_NODE_CLASSES_BY_TAG, NODE_CONVERTERS,
OBJECT_NODE_CLASSES_BY_TAG, SCALAR_NODE_CLASSES_BY_TAG)

from ._registry import LIST_NODE_CLASSES_BY_TAG, NODE_CONVERTERS, OBJECT_NODE_CLASSES_BY_TAG, SCALAR_NODE_CLASSES_BY_TAG

__all__ = [
"TaggedObjectNodeConverter",
Expand Down Expand Up @@ -114,6 +114,7 @@ def from_yaml_tree(self, node, tag, ctx):

return SCALAR_NODE_CLASSES_BY_TAG[tag](node)


# The following converters are intended allow the current node behavior of
# accessing node attributes that are simple lists and dicts and returning
# them as LNode and DNode instances so that the attribute machinery works
Expand All @@ -126,6 +127,7 @@ def from_yaml_tree(self, node, tag, ctx):
# and not for deserializing since there are no tags that can be used for
# that.


class DNodeConverter(Converter):
tags = []
types = ["roman_datamodels.stnode._node.DNode"]
Expand All @@ -142,7 +144,7 @@ def from_yaml_tree(self, node, tag, ctx):


class LNodeConverter(Converter):
tags =[]
tags = []
types = ["roman_datamodels.stnode._node.LNode"]

def select_tag(self, obj, tags, ctx):
Expand All @@ -155,9 +157,9 @@ def to_yaml_tree(self, obj, tag, ctx):
def from_yaml_tree(self, node, tag, ctx):
raise NotImplementedError()


# Create the ASDF extension for the STNode classes.
NODE_EXTENSIONS = [
ManifestExtension.from_uri("asdf://stsci.edu/datamodels/roman/manifests/datamodels-1.0",
converters=NODE_CONVERTERS.values()),
ManifestExtension.from_uri("asdf://stsci.edu/datamodels/roman/manifests/datamodels-1.0", converters=NODE_CONVERTERS.values()),
ManifestExtension(None, converters=[DNodeConverter(), LNodeConverter()]),
]
1 change: 1 addition & 0 deletions src/roman_datamodels/stnode/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from astropy.time import Time

from roman_datamodels.validate import ValidationWarning, _check_type, _error_message, will_strict_validate, will_validate

from ._registry import SCALAR_NODE_CLASSES_BY_KEY

__all__ = ["DNode", "LNode"]
Expand Down

0 comments on commit 19f7b8e

Please sign in to comment.