Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bo4e/com/com.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class COM(BaseModel):
# an annotated version of Decimal, but you would have to use it everywhere in the pydantic models.
# See this issue for more info: https://github.com/pydantic/pydantic/issues/6375
json_encoders={Decimal: str},
use_attribute_docstrings=True,
)
"""
basic configuration for pydantic's behaviour
Expand Down
8 changes: 1 addition & 7 deletions src/bo4e/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def add_comments_to_description(cls: type[T]) -> type[T]:
# https://regex101.com/r/aJrvol/1
regex_comment_inline = r"{field_name}:[^:]*#: ?(?P<comment>[^\n]*)\n"
# https://regex101.com/r/0PaUmw/1
regex_comment_below = r"{field_name}:[^:]*\n(?P<indent> +)\"{3}(?P<comment>(?:\"{0,2}[^\"])*)\"{3}"
# https://regex101.com/r/9HhOlD/1

for field_name, field_info in cls.model_fields.items():
if field_info.description is not None:
Expand All @@ -44,11 +42,7 @@ def add_comments_to_description(cls: type[T]) -> type[T]:
if match is not None:
field_info.description = match.group("comment").strip()
continue
# search for (multi line) comments below the field
match = re.search(regex_comment_below.replace("{field_name}", field_name), fields_code)
if match is not None:
field_info.description = match.group("comment").strip().replace("\n" + match.group("indent"), "\n")
continue
# (multi line) comments below the field aka docstrings are now handled by pydantic
# Try to find the comment in the bases
description = None
for base in cls.__bases__:
Expand Down