From 4dd909bb3b938c66d656ca78c542fcd227ebf950 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Mon, 9 Oct 2023 22:06:27 +0200 Subject: [PATCH] remove python2 crumbs --- requirements.txt | 1 - setup.py | 2 +- treelib/__init__.py | 13 +------------ treelib/node.py | 4 +--- treelib/tree.py | 26 ++++++-------------------- 5 files changed, 9 insertions(+), 37 deletions(-) diff --git a/requirements.txt b/requirements.txt index 63a9655..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -six>=1.13.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 9331bec..178ec9b 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ license="Apache License, Version 2.0", packages=["treelib"], keywords=["data structure", "tree", "tools"], - install_requires=["six"], + install_requires=[], classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console", diff --git a/treelib/__init__.py b/treelib/__init__.py index 4902412..677c57d 100644 --- a/treelib/__init__.py +++ b/treelib/__init__.py @@ -17,22 +17,11 @@ # See the License for the specific language governing permissions and # limitations under the License. """ -treelib - Python 2/3 Tree Implementation +treelib - Python Tree Implementation `treelib` is a Python module with two primary classes: Node and Tree. Tree is a self-contained structure with some nodes and connected by branches. A tree owns merely a root, while a node (except root) has some children and one parent. - -Note: To solve string compatibility between Python 2.x and 3.x, treelib follows -the way of porting Python 3.x to 2/3. That means, all strings are manipulated as -unicode and you do not need u'' prefix anymore. The impacted functions include `str()`, -`show()` and `save2file()` routines. -But if your data contains non-ascii characters and Python 2.x is used, -you have to trigger the compatibility by declaring `unicode_literals` in the code: - -.. code-block:: python - - >>> from __future__ import unicode_literals """ from .tree import Tree # noqa: F401 diff --git a/treelib/node.py b/treelib/node.py index 958c734..c069e76 100644 --- a/treelib/node.py +++ b/treelib/node.py @@ -23,8 +23,6 @@ A :class:`Node` object contains basic properties such as node identifier, node tag, parent node, children nodes etc., and some operations for a node. """ -from __future__ import unicode_literals - import copy import uuid from collections import defaultdict @@ -34,7 +32,7 @@ from .misc import deprecated -class Node(object): +class Node: """ Nodes are elementary objects that are stored in the `_nodes` dictionary of a Tree. Use `data` attribute to store node-specific data. diff --git a/treelib/tree.py b/treelib/tree.py index 1cc9ac8..cbd4d12 100644 --- a/treelib/tree.py +++ b/treelib/tree.py @@ -26,24 +26,11 @@ When deep=True, a deepcopy operation is performed on feeding tree parameter and more memory is required to create the tree. """ -from __future__ import print_function -from __future__ import unicode_literals - -try: - from builtins import str as text -except ImportError: - from __builtin__ import str as text - import codecs import json import uuid from copy import deepcopy -from six import python_2_unicode_compatible, iteritems - -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import StringIO from .exceptions import ( NodeIDAbsentError, @@ -58,8 +45,7 @@ __author__ = "chenxm" -@python_2_unicode_compatible -class Tree(object): +class Tree: """Tree objects are made of Node(s) stored in _nodes dictionary.""" #: ROOT, DEPTH, WIDTH, ZIGZAG constants : @@ -89,7 +75,7 @@ def __init__(self, tree=None, deep=False, node_class=None, identifier=None): 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: @@ -687,9 +673,9 @@ def paste(self, nid, new_tree, deep=False): 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}) @@ -1017,7 +1003,7 @@ def update_node(self, nid, **attrs): :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