You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/contents/getting-started.rst
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,15 +41,15 @@ Inheritence
41
41
Setting or assigning values
42
42
---------------------------
43
43
44
-
Instead of raising an :code:`AttributeError`, reading a new attribute on an :code:`easytree.dict` creates and returns a new child :code:`Node`.
44
+
Instead of raising an :code:`AttributeError`, reading a new attribute on an :code:`easytree.dict` returns a new :code:`undefined` node.
45
45
46
46
.. code-block::
47
47
48
48
>>> tree = easytree.dict()
49
-
>>> tree.address # new undefined node
50
-
<Node 'address'>
49
+
>>> tree.address # undefined node
50
+
<undefined 'address'>
51
51
52
-
Reading or setting an attribute on such child node dynamically *casts* it as an :code:`easytree.dict`.
52
+
Reading or setting an attribute on such child node dynamically *casts* it as an :code:`easytree.dict` and assigns it to its parent.
53
53
54
54
.. code-block::
55
55
@@ -63,11 +63,11 @@ Alternatively, using a list method such as :code:`append` dynamically *casts* th
63
63
.. code-block::
64
64
65
65
>>> tree = easytree.dict()
66
-
>>> tree.address
67
-
<Node 'address'>
66
+
>>> tree.address # undefined node
67
+
<undefined 'address'>
68
68
69
69
>>> tree.address.country.append("United States")
70
-
>>> tree.address
70
+
>>> tree.address # now a dict
71
71
{"country": ["United States"]}
72
72
73
73
@@ -85,7 +85,7 @@ Of course, you can use the dot or bracket notation interchangeably, both to read
85
85
"bar"
86
86
87
87
.. note::
88
-
The bracket notation remains necessary if the key is not a valid attribute identifier name.
88
+
The bracket notation remains necessary if the key is not a valid attribute identifier name, or if the key is identical to a :code:`dict` method name.
89
89
90
90
.. code-block::
91
91
@@ -119,15 +119,15 @@ Dictionaries assigned to an :code:`easytree.dict` or added to an :code:`easytree
119
119
]
120
120
121
121
122
-
Lists assigned to an :code:`easytree.dict` are *cast* as :code:`easytree.list` instances.
122
+
Lists assigned to an :code:`easytree.dict` are also *cast* as :code:`easytree.list` instances.
123
123
124
124
.. code-block::
125
125
126
126
>>> tree = easytree.dict({"numbers": [1,3,5]})
127
127
>>> isinstance(tree.numbers, easytree.list)
128
128
True
129
129
130
-
Tuple values assigned to an :code:`easytree.dict` are also *cast*.
130
+
Tuple values assigned to an :code:`easytree.dict` are also *cast* as tuples of :code:`easytree` objects.
131
131
132
132
.. code-block::
133
133
@@ -206,15 +206,15 @@ Because the :code:`append` method returns a reference to the last appended item,
206
206
207
207
The undefined node
208
208
------------------
209
-
An :code:`undefined` node object created when an undefined attribute is read from an :code:`easytree.dict` node.
209
+
An :code:`undefined` node object is returned when an undefined attribute is read from an :code:`easytree.dict` node. This falsy object contains a reference to its parent object, as well as the key from which this object was returned.
210
210
211
211
.. code-block::
212
212
213
213
>>> person = easytree.dict()
214
214
>>> person.address
215
-
<Node 'address'>
215
+
<undefined 'address'>
216
216
217
-
Assigning or reading an attribute from an :code:`undefined` node *casts* it as a dictionary.
217
+
Assigning or reading an attribute from an :code:`undefined` node *casts* it as a dictionary. This is possible since the :code:`undefined` object keeps a reference to its parent and the key from which it was returned.
218
218
219
219
.. code-block::
220
220
@@ -249,7 +249,7 @@ By definition, and unless an easytree is sealed or frozen, reading an undefined
0 commit comments