Skip to content

NamedType

Bases: AbstractType

Source code in library_analyzer/processing/api/model/_types.py
@dataclass
class NamedType(AbstractType):
    name: str

    @classmethod
    def from_json(cls, json: Any) -> Optional[NamedType]:
        if json.get("kind", "") == cls.__name__:
            return NamedType(json["name"])
        return None

    @classmethod
    def from_string(cls, string: str) -> NamedType:
        return NamedType(string)

    def to_json(self) -> dict[str, str]:
        return {"kind": self.__class__.__name__, "name": self.name}

    def __eq__(self, other: object) -> bool:
        if isinstance(other, self.__class__):
            return self.name == other.name
        return False

    def __hash__(self) -> int:
        return hash(self.name)

name: str class-attribute

__eq__(other)

Source code in library_analyzer/processing/api/model/_types.py
def __eq__(self, other: object) -> bool:
    if isinstance(other, self.__class__):
        return self.name == other.name
    return False

__hash__()

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

from_json(json) classmethod

Source code in library_analyzer/processing/api/model/_types.py
@classmethod
def from_json(cls, json: Any) -> Optional[NamedType]:
    if json.get("kind", "") == cls.__name__:
        return NamedType(json["name"])
    return None

from_string(string) classmethod

Source code in library_analyzer/processing/api/model/_types.py
@classmethod
def from_string(cls, string: str) -> NamedType:
    return NamedType(string)

to_json()

Source code in library_analyzer/processing/api/model/_types.py
def to_json(self) -> dict[str, str]:
    return {"kind": self.__class__.__name__, "name": self.name}