Skip to content

Commit

Permalink
Exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovo committed Sep 30, 2024
1 parent e560ddb commit 2de131c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dikdik"
version = "0.1.6"
version = "0.1.7"
description = "dikdik - Common utils library"
authors = ["Manuel Bovo <[email protected]>"]
readme = "README.md"
Expand Down
5 changes: 5 additions & 0 deletions src/dikdik/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import dict as _dict
from . import yaml as _yaml

Yaml = _yaml
Dict = _dict
16 changes: 13 additions & 3 deletions src/dikdik/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing import Any, Union, Tuple
from jsonschema import ValidationError, validate

class PowerDict():
class PowerDict(dict):
'''
Powerdict is an advanced dict class
'''
Expand Down Expand Up @@ -51,15 +51,18 @@ def __delitem__(self, key):
def __iter__(self):
return iter(self._data)

def __contains__(self, key: str) -> bool:
return key in self._data
def __contains__(self, key: object) -> bool:
return self._data.__contains__(key)

def __repr__(self) -> str:
return repr(self._data)

def __str__(self) -> str:
return str(self._data)

def __eq__(self, value: object) -> bool:
return self._data.__eq__(value)

def __copy__(self):
inst = self.__class__.__new__(self.__class__)
inst.__dict__.update(self.__dict__)
Expand Down Expand Up @@ -181,6 +184,13 @@ def from_env(self, prefix: str = ''):
nkey = key[len(prefix):]
self._data[nkey] = value

def from_dict(self, d: dict, merge: bool = False):
if merge:
d = deep_merge(self._data, d)
self.update(d)

def to_dict(self) -> dict:
return self._data

def deep_merge(d1:dict, d2:dict)-> dict:
"""
Expand Down

0 comments on commit 2de131c

Please sign in to comment.