django/django

View on GitHub

Showing 1,782 of 2,090 total issues

Function generate_altered_fields has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

    def generate_altered_fields(self):
        """
        Make AlterField operations, or possibly RemovedField/AddField if alter
        isn't possible.
        """
Severity: Minor
Found in django/db/migrations/autodetector.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

Function handle has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *app_labels, **options):
        self.written_files = []
        self.verbosity = options["verbosity"]
        self.interactive = options["interactive"]
        self.dry_run = options["dry_run"]
Severity: Minor
Found in django/core/management/commands/makemigrations.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

MigrationAutodetector has 48 functions (exceeds 20 allowed). Consider refactoring.
Open

class MigrationAutodetector:
    """
    Take a pair of ProjectStates and compare them to see what the first would
    need doing to make it match the second (the second usually being the
    project's current state).
Severity: Minor
Found in django/db/migrations/autodetector.py - About 6 hrs to fix

    Function fields_for_model has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

    def fields_for_model(
        model,
        fields=None,
        exclude=None,
        widgets=None,
    Severity: Minor
    Found in django/forms/models.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

    Function changelist_view has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

        def changelist_view(self, request, extra_context=None):
            """
            The 'change list' admin view for this model.
            """
            from django.contrib.admin.views.main import ERROR_FLAG
    Severity: Minor
    Found in django/contrib/admin/options.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

    Function _ogrinspect has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

    def _ogrinspect(
        data_source,
        model_name,
        geom_name="geom",
        layer_key=0,
    Severity: Minor
    Found in django/contrib/gis/utils/ogrinspect.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

    Function serialize has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

        def serialize(
            self,
            queryset,
            *,
            stream=None,
    Severity: Minor
    Found in django/core/serializers/base.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 makemigrations.py has 440 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import os
    import sys
    import warnings
    from itertools import takewhile
    
    
    Severity: Minor
    Found in django/core/management/commands/makemigrations.py - About 6 hrs to fix

      Function run has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
      Open

          def run(self):
              def args_to_win(cmdline):
                  changed = False
                  out = []
                  for token in cmdline.split():
      Severity: Minor
      Found in docs/_ext/djangodocs.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

      Consider simplifying this complex logical expression.
      Open

              if (
                  dependency.field_name is None
                  and dependency.type == OperationDependency.Type.CREATE
              ):
                  return (
      Severity: Critical
      Found in django/db/migrations/autodetector.py - About 6 hrs to fix

        File views.py has 428 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import inspect
        from importlib import import_module
        from inspect import cleandoc
        from pathlib import Path
        
        
        Severity: Minor
        Found in django/contrib/admindocs/views.py - About 6 hrs to fix

          Function watched_roots has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
          Open

              def watched_roots(self, watched_files):
                  extra_directories = self.directory_globs.keys()
                  watched_file_dirs = [f.parent for f in watched_files]
                  sys_paths = list(sys_path_directories())
                  return frozenset((*extra_directories, *watched_file_dirs, *sys_paths))
          Severity: Minor
          Found in django/utils/autoreload.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

          Function label_for_field has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
          Open

          def label_for_field(name, model, model_admin=None, return_attr=False, form=None):
              """
              Return a sensible label for a field name. The name can be a callable,
              property (but not created with @property decorator), or the name of an
              object's attribute, as well as a model field, including across related
          Severity: Minor
          Found in django/contrib/admin/utils.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

          Function handle has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle(self, *args, **options):
                  locale = options["locale"]
                  exclude = options["exclude"]
                  self.domain = options["domain"]
                  self.verbosity = options["verbosity"]
          Severity: Minor
          Found in django/core/management/commands/makemessages.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 source.py has 423 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import json
          import os
          import sys
          import uuid
          from ctypes import (
          Severity: Minor
          Found in django/contrib/gis/gdal/raster/source.py - About 6 hrs to fix

            Function init has 153 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    init: function(field_id, field_name, is_stacked) {
                        if (field_id.match(/__prefix__/)) {
                            // Don't initialize on empty forms.
                            return;
                        }
            Severity: Major
            Found in django/contrib/admin/static/admin/js/SelectFilter2.js - About 6 hrs to fix

              Function formset has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
              Open

                  $.fn.formset = function(opts) {
                      const options = $.extend({}, $.fn.formset.defaults, opts);
                      const $this = $(this);
                      const $parent = $this.parent();
                      const updateElementIndex = function(el, prefix, ndx) {
              Severity: Minor
              Found in django/contrib/admin/static/admin/js/inlines.js - 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

              Function condition has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
              Open

              def condition(etag_func=None, last_modified_func=None):
                  """
                  Decorator to support conditional retrieval (or change) for a view
                  function.
              
              
              Severity: Minor
              Found in django/views/decorators/http.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

              Function shortcut has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
              Open

              def shortcut(request, content_type_id, object_id):
                  """
                  Redirect to an object's page based on a content-type ID and an object ID.
                  """
                  # Look up the object, making sure it's got a get_absolute_url() function.
              Severity: Minor
              Found in django/contrib/contenttypes/views.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

              Function add_georss_element has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
              Open

                  def add_georss_element(self, handler, item, w3c_geo=False):
                      """Add a GeoRSS XML element using the given item and handler."""
                      # Getting the Geometry object.
                      geom = item.get("geometry")
                      if geom is not None:
              Severity: Minor
              Found in django/contrib/gis/feeds.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

              Severity
              Category
              Status
              Source
              Language