Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove python2 crumbs #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
six>=1.13.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 1 addition & 12 deletions treelib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions treelib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
26 changes: 6 additions & 20 deletions treelib/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 :
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down