<commit_before># Lint as: python3
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""A `traverse` visitor for processing documentation."""

import collections
import inspect

from typing import Any, Dict, List, Optional, Tuple

ApiPath = Tuple[str, ...]


def maybe_singleton(py_object: Any) -> bool:
  """Returns `True` if `py_object` might be a singleton value .

  Many immutable values in python act like singletons: small ints, some strings,
  Bools, None, the empty tuple.

  We can't rely on looking these up by their `id()` to find their name or
  duplicates.

  This function checks if the object is one of those maybe singleton values.

  Args:
    py_object: the object to check.

  Returns:
    A bool, True if the object might be a singleton.
  """
  # isinstance accepts nested tuples of types.
  immutable_types = (int, str, bytes, float, complex, bool, type(None))
  is_immutable_type = isinstance(py_object, immutable_types)

  # Check if the object is the empty tuple.
  return is_immutable_type or py_object == ()


class ApiTreeNode(object):
  """Represents a single API end-point.

  Attributes:
    path: A tuple of strings containing the path to the object from the root
      like `('tf', 'losses', 'hinge')`
    obj: The python object.
    children: A dictionary from short name to `ApiTreeNode`, including the<commit_msg>Fix error when py_object has custom `__eq__`<commit_after># Lint as: python3
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""A `traverse` visitor for processing documentation."""

import collections
import inspect

from typing import Any, Dict, List, Optional, Tuple

ApiPath = Tuple[str, ...]


def maybe_singleton(py_object: Any) -> bool:
  """Returns `True` if `py_object` might be a singleton value .

  Many immutable values in python act like singletons: small ints, some strings,
  Bools, None, the empty tuple.

  We can't rely on looking these up by their `id()` to find their name or
  duplicates.

  This function checks if the object is one of those maybe singleton values.

  Args:
    py_object: the object to check.

  Returns:
    A bool, True if the object might be a singleton.
  """
  # isinstance accepts nested tuples of types.
  immutable_types = (int, str, bytes, float, complex, bool, type(None))
  is_immutable_type = isinstance(py_object, immutable_types)

  # Check if the object is the empty tuple.
  return is_immutable_type or (isinstance(py_object, tuple) and py_object == ())  # pylint: disable=g-explicit-bool-comparison


class ApiTreeNode(object):
  """Represents a single API end-point.

  Attributes:
    path: A tuple of strings containing the path to the object from the root
      like `('tf', 'losses', 'hinge')`
    obj: The python object.
    children: A dictionary from short name to `ApiTreeNode`, including the
{'fraction_non_alphanumeric': 0.11570450097847358, 'fraction_numerical': 0.004403131115459882, 'mean_word_length': 4.182509505703422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485914', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1087, 'n_words': 520}