tensorflow/tensorflow

View on GitHub
tensorflow/python/util/nest_util.py

Summary

Maintainability
F
5 days
Test Coverage

File nest_util.py has 1350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2023 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
Severity: Major
Found in tensorflow/python/util/nest_util.py - About 3 days to fix

    Function sequence_like has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def sequence_like(instance, args):
      """Converts the sequence `args` to the same type as `instance`.
    
      Args:
        instance: an instance of `tuple`, `list`, `namedtuple`, `dict`,
    Severity: Minor
    Found in tensorflow/python/util/nest_util.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _tf_core_yield_sorted_items has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def _tf_core_yield_sorted_items(iterable):
      """Yield (key, value) pairs for `iterable` in a deterministic order.
    
      For Sequences, the key will be an int, the array index of a value.
      For Mappings, the key will be the dictionary key.
    Severity: Minor
    Found in tensorflow/python/util/nest_util.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _tf_data_yield_value has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _tf_data_yield_value(iterable):
      """Yield elements of `iterable` in a deterministic order.
    
      Args:
        iterable: an iterable.
    Severity: Minor
    Found in tensorflow/python/util/nest_util.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _tf_core_pack_sequence_as has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _tf_core_pack_sequence_as(
        structure, flat_sequence, expand_composites, sequence_fn=None
    ):
      """Implements sequence packing, with the option to alter the structure."""
      is_nested_fn = (
    Severity: Minor
    Found in tensorflow/python/util/nest_util.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _tf_core_packed_nest_with_indices has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _tf_core_packed_nest_with_indices(
    Severity: Minor
    Found in tensorflow/python/util/nest_util.py - About 35 mins to fix

      Function yield_flat_up_to has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def yield_flat_up_to(modality, shallow_tree, input_tree, is_nested_fn, path=()):
      Severity: Minor
      Found in tensorflow/python/util/nest_util.py - About 35 mins to fix

        Function assert_shallow_structure has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def assert_shallow_structure(
        Severity: Minor
        Found in tensorflow/python/util/nest_util.py - About 35 mins to fix

          Function assert_same_structure has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def assert_same_structure(
          Severity: Minor
          Found in tensorflow/python/util/nest_util.py - About 35 mins to fix

            Function pack_sequence_as has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def pack_sequence_as(
            Severity: Minor
            Found in tensorflow/python/util/nest_util.py - About 35 mins to fix

              Avoid too many return statements within this function.
              Open

                  return type(instance)(sequence_like(instance.__wrapped__, args))
              Severity: Major
              Found in tensorflow/python/util/nest_util.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return instance.__tf_unflatten__(metadata, tuple(args))
                Severity: Major
                Found in tensorflow/python/util/nest_util.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return spec._from_components(args[0])  # pylint: disable=protected-access
                  Severity: Major
                  Found in tensorflow/python/util/nest_util.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return instance._from_components(args[0])  # pylint: disable=protected-access
                    Severity: Major
                    Found in tensorflow/python/util/nest_util.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return sequence_like(list(instance), args)
                      Severity: Major
                      Found in tensorflow/python/util/nest_util.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return type(instance)(args)
                        Severity: Major
                        Found in tensorflow/python/util/nest_util.py - About 30 mins to fix

                          There are no issues that match your filters.

                          Category
                          Status