def map_with_type()

in torchbiggraph/schema.py [0:0]


    def map_with_type(self, data: Any, type_: Type) -> Any:
        # Needs to come first as in this case type_ is an instance, not a class.
        try:
            base_type = unpack_optional(type_)
        except TypeError:
            pass
        else:
            if data is None:
                return None
            return self.map_with_type(data, base_type)
        if isclass(type_) and issubclass(type_, bool):
            return self.map_bool(data)
        if isclass(type_) and issubclass(type_, int):
            return self.map_int(data)
        if isclass(type_) and issubclass(type_, float):
            return self.map_float(data)
        if isclass(type_) and issubclass(type_, str):
            return self.map_str(data)
        if isclass(type_) and issubclass(type_, Enum):
            return self.map_enum(data, type_)
        if has_origin(type_, list):
            return self.map_list(data, type_)
        if has_origin(type_, dict):
            return self.map_dict(data, type_)
        if isclass(type_) and issubclass(type_, Schema):
            return self.map_schema(data, type_)
        raise NotImplementedError("Unknown type: %s" % type_)