dmyersturnbull/pocketutils

View on GitHub
src/pocketutils/tools/json_tools.py

Summary

Maintainability
D
2 days
Test Coverage

Function prepare has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

    def prepare(
        self: Self,
        data: Any,
        *,
        inf_handling: NanInfHandling,
Severity: Minor
Found in src/pocketutils/tools/json_tools.py - About 6 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

File json_tools.py has 254 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# SPDX-FileCopyrightText: Copyright 2020-2023, Contributors to pocketutils
# SPDX-PackageHomePage: https://github.com/dmyersturnbull/pocketutils
# SPDX-License-Identifier: Apache-2.0
"""

Severity: Minor
Found in src/pocketutils/tools/json_tools.py - About 2 hrs to fix

    Function __call__ has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def __call__(self: Self, obj: Any) -> Any:
            """
            Tries to return a serializable result for `obj`.
            Meant to be passed as `default=` in `orjson.dumps`.
            Only encodes types that can always be represented exactly,
    Severity: Minor
    Found in src/pocketutils/tools/json_tools.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 new_default has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def new_default(
            self: Self,
            *fallbacks: Callable[[Any], Any] | None,
            first: Callable[[Any], Any] | None = _misc_types_default,
            last: Callable[[Any], Any] | None = str,
    Severity: Minor
    Found in src/pocketutils/tools/json_tools.py - About 45 mins 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 encoder has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def encoder(
    Severity: Minor
    Found in src/pocketutils/tools/json_tools.py - About 45 mins to fix

      Consider simplifying this complex logical expression.
      Open

              if (
                  (is_list_with_inf or is_np_array_with_inf or is_list_with_nan or is_list_with_nan)
                  and inf_handling is NanInfHandling.convert_to_str
                  and nan_handling is NanInfHandling.convert_to_str
              ):
      Severity: Major
      Found in src/pocketutils/tools/json_tools.py - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

                if (
                    (is_list_with_inf or is_np_array_with_inf)
                    and (is_list_with_nan or is_list_with_nan)
                    and inf_handling is NanInfHandling.convert_to_str
                    and nan_handling is NanInfHandling.convert_to_null
        Severity: Major
        Found in src/pocketutils/tools/json_tools.py - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

                  if (
                      (is_list_with_inf or is_np_array_with_inf)
                      and (is_list_with_nan or is_list_with_nan)
                      and inf_handling is NanInfHandling.convert_to_null
                      and nan_handling is NanInfHandling.convert_to_str
          Severity: Major
          Found in src/pocketutils/tools/json_tools.py - About 40 mins to fix

            Avoid too many return statements within this function.
            Open

                        return obj._asdict()
            Severity: Major
            Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return data.tolist()
              Severity: Major
              Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return [self.prepare(e, inf_handling=inf_handling, nan_handling=nan_handling) for e in data]
                Severity: Major
                Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return str(data)
                  Severity: Major
                  Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return obj.Self
                    Severity: Major
                    Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return base64.b64decode(obj)
                      Severity: Major
                      Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return dict(obj)
                        Severity: Major
                        Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return data
                          Severity: Major
                          Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return obj.tzname(datetime.now(tz=obj))
                            Severity: Major
                            Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return list(obj)
                              Severity: Major
                              Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return base64.b64decode(bytes(obj))
                                Severity: Major
                                Found in src/pocketutils/tools/json_tools.py - About 30 mins to fix

                                  There are no issues that match your filters.

                                  Category
                                  Status