django/django

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

Summary

Maintainability
C
1 day
Test Coverage

File widgets.py has 488 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Form Widget classes specific to the Django admin site.
"""

import copy
Severity: Minor
Found in django/contrib/admin/widgets.py - About 7 hrs to fix

    Function url_params_from_lookup_dict has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def url_params_from_lookup_dict(lookups):
        """
        Convert the type of lookups specified in a ForeignKey limit_choices_to
        attribute to a dictionary of query parameters
        """
    Severity: Minor
    Found in django/contrib/admin/widgets.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 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Major
    Found in django/contrib/admin/widgets.py - About 50 mins to fix

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

          def get_context(self, name, value, attrs):
              context = super().get_context(name, value, attrs)
              rel_to = self.rel.model
              if self.admin_site.is_registered(rel_to):
                  # The related object is registered with the same AdminSite
      Severity: Minor
      Found in django/contrib/admin/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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, verbose_name, is_stacked, attrs=None, choices=()):
      Severity: Minor
      Found in django/contrib/admin/widgets.py - About 35 mins to fix

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

            def __init__(self, field, admin_site, attrs=None, choices=(), using=None):
        Severity: Minor
        Found in django/contrib/admin/widgets.py - About 35 mins to fix

          Function get_select2_language has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_select2_language():
              lang_code = get_language()
              supported_code = SELECT2_TRANSLATIONS.get(lang_code)
              if supported_code is None and lang_code is not None:
                  # If 'zh-hant-tw' is not supported, try subsequent language codes i.e.
          Severity: Minor
          Found in django/contrib/admin/widgets.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

          There are no issues that match your filters.

          Category
          Status