django/django

View on GitHub
django/contrib/postgres/fields/array.py

Summary

Maintainability
C
1 day
Test Coverage

File array.py has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json

from django.contrib.postgres import lookups
from django.contrib.postgres.forms import SimpleArrayField
from django.contrib.postgres.validators import ArrayMaxLengthValidator
Severity: Minor
Found in django/contrib/postgres/fields/array.py - About 3 hrs to fix

    ArrayField has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ArrayField(CheckFieldDefaultMixin, Field):
        empty_strings_allowed = False
        default_error_messages = {
            "item_invalid": _("Item %(nth)s in the array did not validate:"),
            "nested_array_mismatch": _("Nested arrays must have the same length."),
    Severity: Minor
    Found in django/contrib/postgres/fields/array.py - About 2 hrs to fix

      Function check has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def check(self, **kwargs):
              errors = super().check(**kwargs)
              if self.base_field.remote_field:
                  errors.append(
                      checks.Error(
      Severity: Minor
      Found in django/contrib/postgres/fields/array.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 __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, lhs, rhs):
              # Don't wrap arrays that contains only None values, psycopg doesn't
              # allow this.
              if isinstance(rhs, (tuple, list)) and any(self._rhs_not_none_values(rhs)):
                  expressions = []
      Severity: Minor
      Found in django/contrib/postgres/fields/array.py - About 35 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 get_transform has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_transform(self, name):
              transform = super().get_transform(name)
              if transform:
                  return transform
              if "_" not in name:
      Severity: Minor
      Found in django/contrib/postgres/fields/array.py - About 35 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 validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate(self, value, model_instance):
              super().validate(value, model_instance)
              for index, part in enumerate(value):
                  try:
                      self.base_field.validate(part, model_instance)
      Severity: Minor
      Found in django/contrib/postgres/fields/array.py - About 25 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

      There are no issues that match your filters.

      Category
      Status