django/django

View on GitHub
django/contrib/admin/helpers.py

Summary

Maintainability
C
1 day
Test Coverage

File helpers.py has 336 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json

from django import forms
from django.conf import settings
from django.contrib.admin.utils import (
Severity: Minor
Found in django/contrib/admin/helpers.py - About 4 hrs to fix

    Function contents has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def contents(self):
            from django.contrib.admin.templatetags.admin_list import _boolean_icon
            field, obj, model_admin = self.field['field'], self.form.instance, self.model_admin
            try:
                f, attr, value = lookup_field(field, obj, model_admin)
    Severity: Minor
    Found in django/contrib/admin/helpers.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 fields has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def fields(self):
            fk = getattr(self.formset, "fk", None)
            empty_form = self.formset.empty_form
            meta_labels = empty_form._meta.labels or {}
            meta_help_texts = empty_form._meta.help_texts or {}
    Severity: Minor
    Found in django/contrib/admin/helpers.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 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, inline, formset, fieldsets, prepopulated_fields=None,
    Severity: Major
    Found in django/contrib/admin/helpers.py - About 1 hr to fix

      Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, formset, form, fieldsets, prepopulated_fields, original,
      Severity: Major
      Found in django/contrib/admin/helpers.py - About 1 hr to fix

        Function __init__ has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, form, field, is_first, model_admin=None):
                # Make self.field look a little bit like a field. This means that
                # {{ field.name }} must be a useful class name to identify the field.
                # For convenience, store other field-related data here too.
                if callable(field):
        Severity: Minor
        Found in django/contrib/admin/helpers.py - About 55 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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(),
        Severity: Major
        Found in django/contrib/admin/helpers.py - About 50 mins to fix

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

              def __init__(self, form, fieldsets, prepopulated_fields, readonly_fields=None, model_admin=None):
          Severity: Minor
          Found in django/contrib/admin/helpers.py - About 35 mins to fix

            Function __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def __init__(self, form, inline_formsets):
                    super().__init__()
            
                    if form.is_bound:
                        self.extend(form.errors.values())
            Severity: Minor
            Found in django/contrib/admin/helpers.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