Skip to content

Commit

Permalink
update serialization for new monty
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Jul 13, 2021
1 parent f651d54 commit 36c2698
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions emmet-core/emmet/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Dict, List, Type, TypeVar, Union

import requests
from monty.json import MontyDecoder
from pydantic import BaseSettings, Field, root_validator
from pydantic.types import PyObject

Expand Down Expand Up @@ -118,15 +119,13 @@ def autoload(cls: Type[S], settings: Union[None, dict, S]) -> S:
return cls(**settings)
return settings

def as_dict(self):
"""
HotPatch to enable serializing EmmetSettings via Monty
"""
return self.dict(exclude_unset=True, exclude_defaults=True)

@classmethod
def from_dict(cls: Type[S], settings: Dict) -> S:
"""
HotPatch to enable serializing EmmetSettings via Monty
"""
return cls(**settings)
def from_dict(cls, data):
""" Custom from_dict because monty serializaiton is currently broken """
decoder = MontyDecoder()
data = {
decoder.process_decoded(k): decoder.process_decoded(v)
for k, v in data.items()
if not k.startswith("@")
}
return cls(**data)

0 comments on commit 36c2698

Please sign in to comment.