1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
From: Alexandre Detiste <alexandre.detiste@gmail.com>, ngraves@ngraves.fr
diff --git a/pyproject.toml b/pyproject.toml
index 98b5603..7b192a8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -35,7 +35,6 @@ include = [
[tool.poetry.dependencies]
python = "^3.7"
-six = ">=1.13.0"
[tool.poetry.group.dev.dependencies]
# Testing dependencies - pytest for all Python versions
diff --git a/treelib/__init__.py b/treelib/__init__.py
index bed89cc..f164208 100644
--- a/treelib/__init__.py
+++ b/treelib/__init__.py
@@ -57,15 +57,6 @@ Common Use Cases:
- Abstract syntax trees
- Family trees and genealogy
-Compatibility Note:
- To ensure string compatibility between Python 2.x and 3.x, treelib follows
- Python 3.x string handling conventions. All strings are handled as unicode.
-
- For Python 2.x users with non-ASCII characters, enable unicode literals:
-
- .. code-block:: python
-
- from __future__ import unicode_literals
"""
from .node import Node # noqa: F401
diff --git a/treelib/node.py b/treelib/node.py
index cb79a01..64547f7 100644
--- a/treelib/node.py
+++ b/treelib/node.py
@@ -22,8 +22,6 @@ Note:
directly instantiated, as the Tree class manages the parent-child
relationships automatically.
"""
-from __future__ import unicode_literals
-
import copy
import sys
import uuid
@@ -40,7 +38,7 @@ else:
StrList = List[str] # Python 3.8 and earlier
-class Node(object):
+class Node:
"""
Elementary node object stored in Tree structures.
diff --git a/treelib/tree.py b/treelib/tree.py
index 39bbdb5..8042175 100644
--- a/treelib/tree.py
+++ b/treelib/tree.py
@@ -26,26 +26,13 @@ Key Features:
- Subtree operations and filtering
- Tree metrics and analysis tools
"""
-from __future__ import print_function, unicode_literals
-
-try:
- from builtins import str as text
-except ImportError:
- from __builtin__ import str as text # type: ignore
-
import codecs
import json
import sys
import uuid
from copy import deepcopy
from typing import Any, Callable, List, Optional, Union, cast
-
-from six import iteritems, python_2_unicode_compatible
-
-try:
- from StringIO import StringIO # type: ignore
-except ImportError:
- from io import StringIO
+from io import StringIO
from .exceptions import (
DuplicatedNodeIdError,
@@ -70,8 +57,7 @@ else:
__author__ = "chenxm"
-@python_2_unicode_compatible
-class Tree(object):
+class Tree():
"""
Hierarchical tree data structure.
@@ -220,7 +206,7 @@ class Tree(object):
if tree is not None:
self.root = tree.root
- for nid, node in iteritems(tree.nodes):
+ for nid, node in tree.nodes.items():
new_node = deepcopy(node) if deep else node
self._nodes[nid] = new_node
if tree.identifier != self._identifier:
@@ -1540,9 +1526,9 @@ class Tree(object):
set_joint = set(new_tree._nodes) & set(self._nodes) # joint keys
if set_joint:
- raise ValueError("Duplicated nodes %s exists." % list(map(text, set_joint)))
+ raise ValueError("Duplicated nodes %s exists." % list(map(str, set_joint)))
- for cid, node in iteritems(new_tree.nodes):
+ for cid, node in new_tree.nodes.items():
if deep:
node = deepcopy(new_tree[node])
self._nodes.update({cid: node})
@@ -1909,7 +1895,7 @@ class Tree(object):
:return: None
"""
cn = self[nid]
- for attr, val in iteritems(attrs):
+ for attr, val in attrs.items():
if attr == "identifier":
# Updating node id meets following contraints:
# * Update node identifier property
|