Skip to content

Commit

Permalink
Removed unused imports
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 382309223
  • Loading branch information
superbobry authored and copybara-github committed Jun 30, 2021
1 parent 68abd80 commit b493c39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
62 changes: 26 additions & 36 deletions tree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@

"""Functions for working with nested data structures."""

import collections
from collections import abc as collections_abc
import functools
import logging
import sys
import types
from tree.sequence import _is_attrs
from tree.sequence import _is_namedtuple
from tree.sequence import _sequence_like
from tree.sequence import _sorted
from typing import Mapping, Sequence, Text, TypeVar, Union

from .sequence import _is_attrs
from .sequence import _is_namedtuple
from .sequence import _sequence_like
from .sequence import _sorted

# pylint: disable=g-import-not-at-top
try:
Expand All @@ -34,13 +33,6 @@
class ObjectProxy(object):
"""Stub-class for `wrapt.ObjectProxy``."""

try:
from typing import Any, Mapping, Sequence, Union, Text, TypeVar
except ImportError:
typing_available = False
else:
typing_available = True

try:
from tree import _tree
except ImportError:
Expand Down Expand Up @@ -96,28 +88,26 @@ class ObjectProxy(object):
"If shallow structure is a sequence, input must also be a sequence. "
"Input has type: {}.")

if typing_available:
K = TypeVar("K")
V = TypeVar("V")
# A generic monomorphic structure type, e.g. ``StructureKV[Text, int]``
# is an arbitrarily nested structure where keys must be of type ``Text``
# and values are integers.
# pytype: disable=not-supported-yet
# TODO(b/146184840): Remove pytype disable when recursive types supported
StructureKV = Union[
Sequence["StructureKV[K, V]"],
Mapping[K, "StructureKV[K, V]"],
V,
]
# pytype: enable=not-supported-yet
# A specialization of ``StructureKV`` for the common case of ``Text`` keys.
try:
Structure = StructureKV[Text, V]
except TypeError:
# Older Python 3.5 and 3.6 releases do not always support such use
# of generics. Specialize ``StructureKV`` manually.
Structure = Union[Sequence["Structure[V]"], Mapping[Text, "Structure[V]"],
V]
K = TypeVar("K")
V = TypeVar("V")
# A generic monomorphic structure type, e.g. ``StructureKV[Text, int]``
# is an arbitrarily nested structure where keys must be of type ``Text``
# and values are integers.
# pytype: disable=not-supported-yet
# TODO(b/146184840): Remove disable= when pytype supports recursive types.
StructureKV = Union[
Sequence["StructureKV[K, V]"],
Mapping[K, "StructureKV[K, V]"],
V,
]
# pytype: enable=not-supported-yet
# A specialization of ``StructureKV`` for the common case of ``Text`` keys.
try:
Structure = StructureKV[Text, V]
except TypeError:
# Older Python 3.5 and 3.6 releases do not always support such use
# of generics. Specialize ``StructureKV`` manually.
Structure = Union[Sequence["Structure[V]"], Mapping[Text, "Structure[V]"], V]


def _get_attrs_items(obj):
Expand Down
6 changes: 5 additions & 1 deletion tree/tree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
class DoctestTest(parameterized.TestCase):

def testDoctest(self):
extraglobs = {
"collections": collections,
"tree": tree,
}
num_failed, num_attempted = doctest.testmod(
tree, extraglobs={"tree": tree}, optionflags=doctest.ELLIPSIS)
tree, extraglobs=extraglobs, optionflags=doctest.ELLIPSIS)
self.assertGreater(num_attempted, 0, "No doctests found.")
self.assertEqual(num_failed, 0, "{} doctests failed".format(num_failed))

Expand Down

0 comments on commit b493c39

Please sign in to comment.