django/django

View on GitHub

Showing 1,786 of 2,094 total issues

Avoid deeply nested control flow statements.
Open

                        if self.match is None or self.match_re.search(f):
                            f = os.path.join(root, f)
                            self.choices.append((f, f.replace(path, "", 1)))
        else:
Severity: Major
Found in django/forms/fields.py - About 45 mins to fix

    Function value_from_datadict has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def value_from_datadict(self, data, files, name):
            y = data.get(self.year_field % name)
            m = data.get(self.month_field % name)
            d = data.get(self.day_field % name)
            if y == m == d == "":
    Severity: Minor
    Found in django/forms/widgets.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 run_validators has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def run_validators(self, value):
            if value in self.empty_values:
                return
            errors = []
            for v in self.validators:
    Severity: Minor
    Found in django/forms/fields.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 create_permissions has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def create_permissions(
    Severity: Minor
    Found in django/contrib/auth/management/__init__.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if date_range["first"].month == date_range["last"].month:
                              month_lookup = date_range["first"].month
      
      
      Severity: Major
      Found in django/contrib/admin/templatetags/admin_list.py - About 45 mins to fix

        Function get_results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_results(self, request):
                paginator = self.model_admin.get_paginator(
                    request, self.queryset, self.list_per_page
                )
                # Get the number of objects, with admin filters applied.
        Severity: Minor
        Found in django/contrib/admin/views/main.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 get_paginator has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def get_paginator(
        Severity: Minor
        Found in django/contrib/admin/options.py - About 45 mins to fix

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

              def __init__(
                  self,
                  data=None,
                  files=None,
                  instance=None,
          Severity: Minor
          Found in django/forms/models.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 get_containing_app_config has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_containing_app_config(self, object_name):
                  """
                  Look for an app config containing a given object.
          
                  object_name is the dotted Python path to the object.
          Severity: Minor
          Found in django/apps/registry.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 as_widget has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def as_widget(self, widget=None, attrs=None, only_initial=False):
                  """
                  Render the field by rendering the passed widget, adding any HTML
                  attributes passed as attrs. If a widget isn't specified, use the
                  field's default widget.
          Severity: Minor
          Found in django/forms/boundfield.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 send_mail has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def send_mail(
          Severity: Minor
          Found in django/contrib/auth/forms.py - About 45 mins to fix

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

                def message_user(
            Severity: Minor
            Found in django/contrib/admin/options.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      for field in unique_check:
                                          if field in form.cleaned_data:
                                              del form.cleaned_data[field]
                                  # mark the data as seen
                                  seen_data.add(row_data)
              Severity: Major
              Found in django/forms/models.py - About 45 mins to fix

                Function get_default_username has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def get_default_username(check_db=True, database=DEFAULT_DB_ALIAS):
                    """
                    Try to determine the current system user's username to use as a default.
                
                    :param check_db: If ``True``, requires that the username does not match an
                Severity: Minor
                Found in django/contrib/auth/management/__init__.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 _check_values has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _check_values(self, value):
                        """
                        Given a list of possible PK values, return a QuerySet of the
                        corresponding objects. Raise a ValidationError if a given value is
                        invalid (not a valid PK, not in the queryset, etc.)
                Severity: Minor
                Found in django/forms/models.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

                Avoid deeply nested control flow statements.
                Open

                                            if not input_value.strip():
                                                user_data[field_name] = None
                                                self.stderr.write("Error: This field cannot be blank.")
                                                continue
                                            user_data[field_name] = [
                Severity: Major
                Found in django/contrib/auth/management/commands/createsuperuser.py - About 45 mins to fix

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

                      def __init__(self, field, request, params, model, model_admin, field_path):
                  Severity: Minor
                  Found in django/contrib/admin/filters.py - About 45 mins to fix

                    Function get_formset has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def get_formset(self, request, obj=None, **kwargs):
                            if "fields" in kwargs:
                                fields = kwargs.pop("fields")
                            else:
                                fields = flatten_fieldsets(self.get_fieldsets(request, obj))
                    Severity: Minor
                    Found in django/contrib/contenttypes/admin.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def __init__(self, field, request, params, model, model_admin, field_path):
                    Severity: Minor
                    Found in django/contrib/admin/filters.py - About 45 mins to fix

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

                      def create_contenttypes(
                      Severity: Minor
                      Found in django/contrib/contenttypes/management/__init__.py - About 45 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language