Skip to content

Commit

Permalink
added dict helper methods. really not feeling dataclasses here.
Browse files Browse the repository at this point in the history
  • Loading branch information
dalejung committed Jun 25, 2023
1 parent 9847e1f commit 3fc4567
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 15 additions & 2 deletions nbx_deux/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,24 @@ def from_filepath(cls, os_path, root_dir=None):
def asdict(self):
return dc.asdict(self)

def __getitem__(self, key):
return getattr(self, key)

def __setitem__(self, key, value):
return setattr(self, key, value)

def __iter__(self):
return iter(self.asdict())

def items(self):
return self.asdict().items()

def keys(self):
return self.asdict().keys()


if __name__ == '__main__':
from pathlib import Path
filepath = Path(__file__)
fcm_model = fcm_base_model(filepath, root_dir=filepath.parents[2])
model = BaseModel.from_filepath(filepath, root_dir=filepath.parents[2])

assert model.asdict() == fcm_model
2 changes: 0 additions & 2 deletions nbx_deux/root_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from nbx_deux.nbx_manager import NBXContentsManager


Expand Down

0 comments on commit 3fc4567

Please sign in to comment.