Skip to content

Commit

Permalink
Added AttrDict object, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
JrooTJunior committed Oct 9, 2021
1 parent 3735a6b commit 0084087
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion magic_filter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import operations
from .attrdict import AttrDict
from .magic import MagicFilter

__all__ = ("operations", "MagicFilter", "F")
__all__ = ("operations", "MagicFilter", "F", "AttrDict")

F = MagicFilter()
14 changes: 14 additions & 0 deletions magic_filter/attrdict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any, Dict, TypeVar

KT = TypeVar("KT")
VT = TypeVar("VT")


class AttrDict(Dict[KT, VT]):
"""
A wrapper over dict which where element can be accessed as regular attributes
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self # type: ignore
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 = "magic-filter"
version = "1.0.2"
version = "1.0.3"
description = "This package provides magic filter based on dynamic attribute getter"
license = "MIT"
readme = "README.md"
Expand Down
15 changes: 15 additions & 0 deletions tests/test_attrdict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from magic_filter import AttrDict


class TestAttrDict:
def test_attrdict(self):
attr = AttrDict({"a": 1, "b": 2, "c": "d"})

assert attr["a"] == 1
assert attr.a == 1

assert attr["b"] == 2
assert attr.b == 2

assert attr["c"] == "d"
assert attr.c == "d"

0 comments on commit 0084087

Please sign in to comment.