Skip to content

Attribute

Source code in library_analyzer/processing/api/model/_api.py
@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
            + ")"
        )

class_id: Optional[str] = None class-attribute

name: str class-attribute

types: Optional[AbstractType] class-attribute

__hash__()

Source code in library_analyzer/processing/api/model/_api.py
def __hash__(self) -> int:
    return hash((self.name, self.class_id, self.types))

__repr__()

Source code in library_analyzer/processing/api/model/_api.py
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
        + ")"
    )

from_json(json, class_id=None) staticmethod

Source code in library_analyzer/processing/api/model/_api.py
@staticmethod
def from_json(json: Any, class_id: Optional[str] = None) -> Attribute:
    return Attribute(
        json["name"], AbstractType.from_json(json.get("types", {})), class_id
    )

to_json()

Source code in library_analyzer/processing/api/model/_api.py
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}