Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
validate dtype and attribute name
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Jan 11, 2024
1 parent f1391c0 commit 907e488
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions sdRDM/markdown/objectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,15 @@ def process_type_option(
del current_attr["default"]

for dtype in dtypes.split(","):
_validate_dtype(dtype, object_stack)

dtype = dtype.strip()

if dtype.endswith("[]"):
dtype = dtype.rstrip("[]")
object_stack[-1]["attributes"][-1]["multiple"] = "True"
del object_stack[-1]["attributes"][-1]["default"]

if not dtype:
continue

Expand All @@ -279,6 +286,25 @@ def process_type_option(
return processed_types


def _validate_dtype(dtype: str, object_stack: List[Dict]) -> None:
"""
Validates the data type of an attribute.
Args:
dtype (str): The data type to validate.
object_stack (List[Dict]): The stack of objects being processed.
Raises:
ValueError: If the attribute has the same name as its type.
"""
attribute = object_stack[-1]["attributes"][-1]

if dtype.rstrip("[]") == attribute["name"]:
raise ValueError(
f"Attribute '{dtype.rstrip('[]')}' has the same name as its type. Please rename it."
)


def is_remote_type(dtype: str) -> bool:
"""Checks whether the given type points to a remote model"""

Expand Down

0 comments on commit 907e488

Please sign in to comment.