Skip to content

Commit 8fa2dac

Browse files
authored
Merge pull request #9 from dschenck/1.0.0
1.0.0
2 parents aac7cd0 + 98dfc80 commit 8fa2dac

File tree

14 files changed

+154
-1408
lines changed

14 files changed

+154
-1408
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 David Schenck
3+
Copyright (c) 2024 David Schenck
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docs/contents/API.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ API
1313
API/easytree.unfreeze
1414
API/easytree.seal
1515
API/easytree.sealed
16-
API/easytree.unseal
17-
API/deprecated
16+
API/easytree.unseal

docs/contents/API/deprecated.rst

Lines changed: 0 additions & 12 deletions
This file was deleted.

docs/contents/changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ Changelog
22
=====================================
33
The source code is hosted and maintained on `github <https://github.com/dschenck/easytree/>`_.
44

5+
Version 1.0.0 (2024-11-12)
6+
--------------------------
7+
- removed deprecated :code:`easytree.Tree` class
8+
- removed deprecated :code:`easytree.Node` class alias
9+
- removed deprecated :code:`easytree.new` function
10+
- removed deprecated :code:`easytree.load` function
11+
- removed deprecated :code:`easytree.loads` function
12+
- removed deprecated :code:`easytree.dump` function
13+
- removed deprecated :code:`easytree.dumps` function
14+
- removed deprecated :code:`easytree.serialize` function
15+
- fixed bug on :code:`easytree.undefined.get`
16+
517
Version 0.2.4 (2023-11-25)
618
--------------------------
719
- fixed a bug where :code:`dict.setdefault` would never set the default value

docs/contents/getting-started.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ Inheritence
4141
Setting or assigning values
4242
---------------------------
4343

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.
4545

4646
.. code-block::
4747
4848
>>> tree = easytree.dict()
49-
>>> tree.address # new undefined node
50-
<Node 'address'>
49+
>>> tree.address # undefined node
50+
<undefined 'address'>
5151
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.
5353

5454
.. code-block::
5555
@@ -63,11 +63,11 @@ Alternatively, using a list method such as :code:`append` dynamically *casts* th
6363
.. code-block::
6464
6565
>>> tree = easytree.dict()
66-
>>> tree.address
67-
<Node 'address'>
66+
>>> tree.address # undefined node
67+
<undefined 'address'>
6868
6969
>>> tree.address.country.append("United States")
70-
>>> tree.address
70+
>>> tree.address # now a dict
7171
{"country": ["United States"]}
7272
7373
@@ -85,7 +85,7 @@ Of course, you can use the dot or bracket notation interchangeably, both to read
8585
"bar"
8686
8787
.. 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.
8989

9090
.. code-block::
9191
@@ -119,15 +119,15 @@ Dictionaries assigned to an :code:`easytree.dict` or added to an :code:`easytree
119119
]
120120
121121
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.
123123

124124
.. code-block::
125125
126126
>>> tree = easytree.dict({"numbers": [1,3,5]})
127127
>>> isinstance(tree.numbers, easytree.list)
128128
True
129129
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.
131131

132132
.. code-block::
133133
@@ -206,15 +206,15 @@ Because the :code:`append` method returns a reference to the last appended item,
206206
207207
The undefined node
208208
------------------
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.
210210

211211
.. code-block::
212212
213213
>>> person = easytree.dict()
214214
>>> person.address
215-
<Node 'address'>
215+
<undefined 'address'>
216216
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.
218218

219219
.. code-block::
220220
@@ -249,7 +249,7 @@ By definition, and unless an easytree is sealed or frozen, reading an undefined
249249
250250
>>> profile = easytree.dict({"firstname":"David"})
251251
>>> profile.firstnam #typo
252-
<Node 'firstnam'>
252+
<undefined 'firstnam'>
253253
254254
Using a numeric key on an undefined node will cast the node as a dictionary, not a list.
255255

docs/contents/sealing-freezing.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
Sealing and freezing
22
=====================================
3-
.. note::
4-
5-
New with version 0.1.8
6-
73
While :code:`easytree` makes it easy to create deeply-nested trees, it can also make it error prone when reading back properties.
84
Sealing and freezing allow to protect trees by restricting some or all mutations to a tree.
95

@@ -43,3 +39,8 @@ Freezing a tree prevents the user from accidentally creating new nodes or changi
4339
AttributeError: cannot set attribute 'city' on frozen node
4440

4541
You can :code:`freeze` and :code:`unfreeze` a tree with the dedicated root-level functions. These functions return a *new* tree (i.e. these functions are not in-place).
42+
::
43+
44+
>>> person = easytree.freeze({"name":"Bob", "address":{"city":"New York"}})
45+
>>> person.address.city = "Los Angeles"
46+
AttributeError: cannot set attribute 'city' on frozen node

docs/contents/subclassing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Subclassing
22
-----------
3-
Starting with version 0.2.1., subclassing :code:`easytree.dict` and :code:`easytree.list` classes is possible.
3+
Subclassing an :code:`easytree.dict` or an :code:`easytree.list` class is possible.
44

55
.. attention::
66
The only requirement is to keep the signature of the :code:`__init__` method unchanged in your subclass. You may amend the actual method, but the signature should remain the same.

easytree/__init__.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
# metadata
2-
__version__ = "0.2.4"
3-
4-
from easytree.tree import (
5-
Node,
6-
serialize,
7-
)
1+
__version__ = "1.0.0"
82

93
from easytree.utils import (
10-
new,
11-
load,
12-
loads,
13-
dump,
14-
dumps,
15-
frozen,
164
freeze,
175
unfreeze,
18-
sealed,
6+
frozen,
197
seal,
208
unseal,
9+
sealed,
2110
)
2211

2312
from easytree.types import dict, list, undefined
2413

25-
# export Node as Tree
26-
Tree = Node
14+
__all__ = [
15+
"dict",
16+
"freeze",
17+
"frozen",
18+
"list",
19+
"seal",
20+
"sealed",
21+
"undefined",
22+
"unfreeze",
23+
"unseal",
24+
]

0 commit comments

Comments
 (0)