Skip to content

Commit

Permalink
fix comment handling (GSI-718) (#33)
Browse files Browse the repository at this point in the history
correctly handle commenting in both datapack contents and schemapack content schemas
  • Loading branch information
KerstenBreuer committed Apr 26, 2024
1 parent f476198 commit 9f9f6bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Using comments in content should not cause any problems
# but did in the past.
datapack: 0.3.0
resources:
SomeClass:
a:
content:
test:
- test # Is this comment causing problems?
relations:
some_relation:
- a
24 changes: 8 additions & 16 deletions src/schemapack/_internals/spec/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,14 @@

"""Custom types annotations used for type hinting."""

from typing import Annotated as _Annotated
from typing import Annotated

from pydantic import Field as _Field
from typing_extensions import TypeAlias as _TypeAlias
from typing_extensions import TypeAlias

__all__ = [
"ClassName",
"ResourceId",
"RelationPropertyName",
"ContentPropertyName",
"IdPropertyName",
]

_NonEmptyStr: _TypeAlias = _Annotated[str, _Field(..., min_length=1)]
ClassName: _TypeAlias = _NonEmptyStr
ResourceId: _TypeAlias = _NonEmptyStr
RelationPropertyName: _TypeAlias = _NonEmptyStr
ContentPropertyName: _TypeAlias = _NonEmptyStr
IdPropertyName: _TypeAlias = _NonEmptyStr
_NonEmptyStr: TypeAlias = Annotated[str, _Field(..., min_length=1)]
ClassName: TypeAlias = _NonEmptyStr
ResourceId: TypeAlias = _NonEmptyStr
RelationPropertyName: TypeAlias = _NonEmptyStr
ContentPropertyName: TypeAlias = _NonEmptyStr
IdPropertyName: TypeAlias = _NonEmptyStr
5 changes: 2 additions & 3 deletions src/schemapack/_internals/spec/datapack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from collections.abc import Iterable
from typing import Annotated, Any, Literal, Optional, Union

import arcticfreeze
from arcticfreeze import FrozenDict
from arcticfreeze import FrozenDict, freeze
from pydantic import BeforeValidator, Field, WrapSerializer
from pydantic_core import PydanticCustomError
from typing_extensions import TypeAlias
Expand Down Expand Up @@ -82,7 +81,7 @@ def validate_duplicate_target_ids(iterable: Iterable) -> Any:
ContentPropertyValue: TypeAlias = Annotated[
Any,
# the value of a content property is deeply frozen:
BeforeValidator(arcticfreeze.freeze),
BeforeValidator(lambda obj: freeze(obj, by_superclass=True)),
]


Expand Down

0 comments on commit 9f9f6bb

Please sign in to comment.