Skip to content

Commit

Permalink
Dot setattr #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sep Dehpour authored and Sep Dehpour committed Dec 30, 2016
1 parent 598199e commit 7ac99eb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DotObject v1.2.0
# DotObject v1.2.1
Dot Notation Object

![Python Versions](https://img.shields.io/pypi/pyversions/dotobject.svg?style=flat)
Expand Down Expand Up @@ -82,6 +82,7 @@ value this.part1.part2.120
```

### Dealing with Dots like dictionary keys
This can be used for setting dynamic key names.

```python
>>> cc = this['part1.part2.part4']
Expand All @@ -90,6 +91,10 @@ value this.part1.part2.120
>>> dd = this['part1.%s.part4' % 100]
>>> dd
<Lazy object: this.part1.100.part4>
>>> path = 'part1.part2'
>>> this[path] = 'This was set by a dynamic key.'
>>> this.path
This was set by a dynamic key.
```

### Saving Dots
Expand Down
9 changes: 7 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**DotObject v 1.2.0**
**DotObject v 1.2.1**

Dot Notation Object

Expand Down Expand Up @@ -78,6 +78,11 @@ Dealing with Dots like dictionary keys
>>> dd = this['part1.%s.part4' % 100]
>>> dd
<Lazy object: this.part1.100.part4>
>>> path = 'part1.part2'
>>> this[path] = 'This was set by a dynamic key.'
>>> this.path
This was set by a dynamic key.


Saving Dots
>>> this.part1.part2.part3.part4 = "new value"
Expand All @@ -102,4 +107,4 @@ Flushing cache
value this.part1
>>> bb = this.part1 # reads from the cache
>>> this.flush()
>>> bb = this.part1 # Will evaluate this.part1 again
>>> bb = this.part1 # Will evaluate this.part1 again
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Install from PyPi::


**************
DotObject 1.2.0
DotObject 1.2.1
**************

.. toctree::
Expand Down
2 changes: 2 additions & 0 deletions dot/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def __setattr__(self, item, value):
else:
self._lazyset_immediate_child(item, value)

__setitem__ = __setattr__

def _load_wrapper(self):
self._threadLock.acquire()
paths_to_eval = tuple(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
long_description = "Dot notation object."

setup(name='dotobject',
version='1.2.0',
version='1.2.1',
description='Dot notation object',
url='https://github.com/seperman/dotobject',
download_url='https://github.com/seperman/dotobject/tarball/master',
Expand Down
7 changes: 7 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def test_getitem(self):
aa = this['part1.part2.part4']
self.assertEqual(str(aa), 'value this.part1.part2.part4')

def test_setitem(self):
this = This()
text = "blah blah"
this['part1.part2.part4'] = text
aa = this.part1.part2.part4
self.assertEqual(aa, text)

def test_change_root_name(self):
this = This(root_name='my')
aa = this.part1.part2.part3.part4
Expand Down

0 comments on commit 7ac99eb

Please sign in to comment.