Пример #1
0
    def from_dict(cls, d):
        """
        Special from_dict to autoload the pydantic model from the location string
        """
        model = d.get("model")
        if isinstance(model, str):
            model = dynamic_import(model)

        assert issubclass(
            model, BaseModel), "The resource model has to be a PyDantic Model"
        d["model"] = model

        return cls(**d)
Пример #2
0
    def from_dict(cls, d):
        if isinstance(d["model"], str):
            d["model"] = dynamic_import(d["model"])

        decoder = MontyDecoder()
        return cls(**{k: decoder.process_decoded(v) for k, v in d.items()})
Пример #3
0
def test_dynamic_import():

    assert dynamic_import("maggma.stores", "MongoStore").__name__ == "MongoStore"
Пример #4
0
    def from_dict(cls, d: Dict):

        if isinstance(d["model"], str):
            d["model"] = dynamic_import(d["model"])
        d = {k: MontyDecoder().process_decoded(v) for k, v in d.items()}
        return cls(**d)