@dataclass
class Attribute:
name: str
types: Optional[AbstractType]
class_id: Optional[str] = None
def __hash__(self) -> int:
return hash((self.name, self.class_id, self.types))
def to_json(self) -> dict[str, Any]:
types_json = self.types.to_json() if self.types is not None else None
return {"name": self.name, "types": types_json}
@staticmethod
def from_json(json: Any, class_id: Optional[str] = None) -> Attribute:
return Attribute(
json["name"], AbstractType.from_json(json.get("types", {})), class_id
)
def __repr__(self) -> str:
type_str = (
" , type=" + str(self.types.to_json()) if self.types is not None else "None"
)
return (
"Attribute(class_id="
+ str(self.class_id)
+ "/"
+ self.name
+ type_str
+ ")"
)