django/django

View on GitHub
django/db/models/base.py

Summary

Maintainability
F
1 wk
Test Coverage

File base.py has 1991 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import inspect
import warnings
from functools import partialmethod
from itertools import chain
Severity: Major
Found in django/db/models/base.py - About 5 days to fix

    Function __new__ has a Cognitive Complexity of 127 (exceeds 5 allowed). Consider refactoring.
    Open

        def __new__(cls, name, bases, attrs, **kwargs):
            super_new = super().__new__
    
            # Also ensure initialization is only performed for subclasses of Model
            # (excluding Model class itself).
    Severity: Minor
    Found in django/db/models/base.py - About 2 days 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 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, *args, **kwargs):
            # Alias some things as locals to avoid repeat global lookups
            cls = self.__class__
            opts = self._meta
            _setattr = setattr
    Severity: Minor
    Found in django/db/models/base.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 _prepare has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def _prepare(cls):
            """Create some methods once self._meta has been populated."""
            opts = cls._meta
            opts._prepare(cls)
    
    
    Severity: Minor
    Found in django/db/models/base.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__ has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def __new__(cls, name, bases, attrs, **kwargs):
            super_new = super().__new__
    
            # Also ensure initialization is only performed for subclasses of Model
            # (excluding Model class itself).
    Severity: Minor
    Found in django/db/models/base.py - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

              if (
                  not cls._meta.abstract
                  and cls._meta.pk.auto_created
                  and
                  # Inherited PKs are checked in parents models.
      Severity: Major
      Found in django/db/models/base.py - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                if (
                    not raw
                    and not force_insert
                    and self._state.adding
                    and (
        Severity: Major
        Found in django/db/models/base.py - About 1 hr to fix

          Function _do_update has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
          Severity: Major
          Found in django/db/models/base.py - About 50 mins to fix

            Function _save_table has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def _save_table(
            Severity: Major
            Found in django/db/models/base.py - About 50 mins to fix

              Function save has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def save(
              Severity: Minor
              Found in django/db/models/base.py - About 45 mins to fix

                Function _do_insert has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def _do_insert(self, manager, using, fields, returning_fields, raw):
                Severity: Minor
                Found in django/db/models/base.py - About 45 mins to fix

                  Function _save_parents has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def _save_parents(
                  Severity: Minor
                  Found in django/db/models/base.py - About 45 mins to fix

                    Function save_base has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def save_base(
                    Severity: Minor
                    Found in django/db/models/base.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if field.one_to_one:
                                                  for parent, parent_link in base_parents.items():
                                                      if field == parent_link:
                                                          base_parents[parent] = new_field
                      
                      
                      Severity: Major
                      Found in django/db/models/base.py - About 45 mins to fix

                        There are no issues that match your filters.

                        Category
                        Status