Skip to content

Commit f8b212f

Browse files
committed
minor code refactor
1 parent 7bc546e commit f8b212f

File tree

7 files changed

+26
-34
lines changed

7 files changed

+26
-34
lines changed

dotwiz/__init__.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
DotWiz is a ``dict`` subclass that enables accessing (nested) keys
66
in dot notation.
77
8-
Sample Usage:
8+
Sample Usage::
99
1010
>>> from dotwiz import DotWiz
11-
>>> dw = DotWiz({'this': {'works': {'for': [{'nested': 'values'}]}}})
11+
>>> dw = DotWiz({'this': {'works': {'for': [{'nested': {'values': True}}]}}},
12+
... the_answer_to_life=42)
1213
>>> dw
13-
DotWiz(this=DotWiz(works=DotWiz(for=[DotWiz(nested='values')])))
14-
>>> dw.this.works['for'][0].nested
15-
'values'
14+
DotWiz(this=DotWiz(works=DotWiz(for=[DotWiz(nested=DotWiz(values=True))])), the_answer_to_life=42)
15+
>>> dw.this.works['for'][0].nested.values
16+
True
17+
>>> dw.the_answer_to_life
18+
42
1619
1720
For full documentation and more advanced usage, please see
1821
<https://dotwiz.readthedocs.io>.

dotwiz/__version__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""
44

55
__title__ = 'dotwiz'
6-
__description__ = 'DotWiz is a dict subclass that enables accessing ' \
7-
'(nested) keys in dot notation.'
6+
__description__ = 'DotWiz is a blazing fast dict subclass that enables ' \
7+
'accessing (nested) keys in dot notation.'
88
__url__ = 'https://github.com/rnag/dotwiz'
99
__version__ = '0.1.0'
1010
__author__ = 'Ritvik Nag'

dotwiz/constants.py

-8
This file was deleted.

dotwiz/constants.pyi

-2
This file was deleted.

dotwiz/main.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
def make_dot_wiz(*args, **kwargs):
55
"""
6-
Helper method to generate and return a `DotWiz` (dot-access dict) from
7-
an optional iterable and *keyword arguments*.
6+
Helper function to create and return a :class:`DotWiz` (dot-access dict)
7+
from an optional *iterable* object and *keyword* arguments.
8+
9+
Example::
10+
11+
>>> from dotwiz import make_dot_wiz
12+
>>> make_dot_wiz([('k1', 11), ('k2', [{'a': 'b'}]), ('k3', 'v3')], y=True)
13+
DotWiz(y=True, k1=11, k2=[DotWiz(a='b')], k3='v3')
814
915
"""
1016
kwargs.update(*args)
@@ -17,8 +23,8 @@ def __upsert_into_dot_wiz__(self, input_dict={},
1723
*, __set=dict.__setitem__,
1824
**kwargs):
1925
"""
20-
Helper method to generate and return a `DotWiz` (dot-access dict) from
21-
a Python `dict` object.
26+
Helper method to generate / update a :class:`DotWiz` (dot-access dict)
27+
from a Python ``dict`` object, and optional *keyword arguments*.
2228
2329
"""
2430
__dict = self.__dict__
@@ -86,8 +92,8 @@ def __convert_to_dict__(o):
8692

8793
class DotWiz(dict):
8894
"""
89-
:class:`DotWiz` - a ``dict`` subclass that also supports dot access
90-
notation.
95+
:class:`DotWiz` - a blazing *fast* ``dict`` subclass that also supports
96+
*dot access* notation.
9197
9298
Usage::
9399
@@ -105,13 +111,6 @@ class DotWiz(dict):
105111
__delattr__ = __delitem__ = dict.__delitem__
106112
__setattr__ = __setitem__ = __setitem_impl__
107113

108-
# TODO do we need this to ensure we raise an `AttributeError`?
109-
# def __getattr__(self, attr):
110-
# try:
111-
# return self.__dict__[attr]
112-
# except KeyError:
113-
# raise AttributeError(attr)
114-
115114
def __getitem__(self, key):
116115
return self.__dict__[key]
117116

dotwiz/main.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypeVar, Callable, Protocol, Mapping, MutableMapping
1+
from typing import TypeVar, Callable, Protocol, Mapping, MutableMapping, Iterable
22

33
_T = TypeVar('_T')
44
_KT = TypeVar('_KT')
@@ -13,7 +13,7 @@ class _Update(Protocol):
1313
**kwargs: _T) -> None: ...
1414

1515

16-
def make_dot_wiz(input_dict: MutableMapping[_KT, _VT] | None = None,
16+
def make_dot_wiz(*args: Iterable[_KT, _VT],
1717
**kwargs: _T) -> DotWiz: ...
1818

1919
# noinspection PyDefaultArgument

tests/unit/test_dotwiz.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def test_dot_wiz_with_basic_usage():
1818

1919
def test_make_dot_wiz():
2020
"""Confirm intended functionality of `make_dot_wiz`"""
21-
dd = make_dot_wiz({1: 'test', 'two': [{'hello': 'world'}]},
21+
dd = make_dot_wiz([(1, 'test'), ('two', [{'hello': 'world'}])],
2222
a=1, b='two', c={'d': [123]})
2323

24-
assert repr(dd) == "DotWiz(1='test', two=[DotWiz(hello='world')], a=1, b='two', c=DotWiz(d=[123]))"
24+
assert repr(dd) == "DotWiz(a=1, b='two', c=DotWiz(d=[123]), 1='test', two=[DotWiz(hello='world')])"
2525
assert dd.a == 1
2626
assert dd.b == 'two'
2727
assert dd[1] == 'test'

0 commit comments

Comments
 (0)