Skip to content

Commit 0084087

Browse files
committed
Added AttrDict object, bump version
1 parent 3735a6b commit 0084087

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

magic_filter/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from . import operations
2+
from .attrdict import AttrDict
23
from .magic import MagicFilter
34

4-
__all__ = ("operations", "MagicFilter", "F")
5+
__all__ = ("operations", "MagicFilter", "F", "AttrDict")
56

67
F = MagicFilter()

magic_filter/attrdict.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import Any, Dict, TypeVar
2+
3+
KT = TypeVar("KT")
4+
VT = TypeVar("VT")
5+
6+
7+
class AttrDict(Dict[KT, VT]):
8+
"""
9+
A wrapper over dict which where element can be accessed as regular attributes
10+
"""
11+
12+
def __init__(self, *args: Any, **kwargs: Any) -> None:
13+
super(AttrDict, self).__init__(*args, **kwargs)
14+
self.__dict__ = self # type: ignore

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "magic-filter"
3-
version = "1.0.2"
3+
version = "1.0.3"
44
description = "This package provides magic filter based on dynamic attribute getter"
55
license = "MIT"
66
readme = "README.md"

tests/test_attrdict.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from magic_filter import AttrDict
2+
3+
4+
class TestAttrDict:
5+
def test_attrdict(self):
6+
attr = AttrDict({"a": 1, "b": 2, "c": "d"})
7+
8+
assert attr["a"] == 1
9+
assert attr.a == 1
10+
11+
assert attr["b"] == 2
12+
assert attr.b == 2
13+
14+
assert attr["c"] == "d"
15+
assert attr.c == "d"

0 commit comments

Comments
 (0)