django/django

View on GitHub
django/forms/fields.py

Summary

Maintainability
F
5 days
Test Coverage

File fields.py has 937 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Field classes.
"""

import copy
Severity: Major
Found in django/forms/fields.py - About 2 days to fix

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

        def __init__(self, path, *, match=None, recursive=False, allow_files=True,
                     allow_folders=False, **kwargs):
            self.path, self.match, self.recursive = path, match, recursive
            self.allow_files, self.allow_folders = allow_files, allow_folders
            super().__init__(choices=(), **kwargs)
    Severity: Minor
    Found in django/forms/fields.py - About 7 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 clean has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        def clean(self, value):
            """
            Validate every value in the given list. A value is validated against
            the corresponding Field in self.fields.
    
    
    Severity: Minor
    Found in django/forms/fields.py - About 4 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 valid_value has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def valid_value(self, value):
            """Check to see if the provided value is a valid choice."""
            text_value = str(value)
            for k, v in self.choices:
                if isinstance(v, (list, tuple)):
    Severity: Minor
    Found in django/forms/fields.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 12 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, *, required=True, widget=None, label=None, initial=None,
    Severity: Major
    Found in django/forms/fields.py - About 1 hr to fix

      Function has_changed has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def has_changed(self, initial, data):
              if self.disabled:
                  return False
              if initial is None:
                  initial = ['' for x in range(0, len(data))]
      Severity: Minor
      Found in django/forms/fields.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__(self, path, *, match=None, recursive=False, allow_files=True,
      Severity: Major
      Found in django/forms/fields.py - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if f == '__pycache__':
                                    continue
                                if self.match is None or self.match_re.search(f):
        Severity: Major
        Found in django/forms/fields.py - About 45 mins to fix

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

              def __init__(self, *, max_value=None, min_value=None, max_digits=None, decimal_places=None, **kwargs):
          Severity: Minor
          Found in django/forms/fields.py - About 45 mins to fix

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

                def __init__(self, *, max_length=None, min_length=None, strip=True, empty_value='', **kwargs):
            Severity: Minor
            Found in django/forms/fields.py - About 45 mins to fix

              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 to_python has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def to_python(self, data):
                      """
                      Check that the file-upload field data contains a valid image (GIF, JPG,
                      PNG, etc. -- whatever Pillow supports).
                      """
              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

              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

                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)))
                                if self.allow_folders:
                Severity: Major
                Found in django/forms/fields.py - About 45 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                                  if (((self.allow_files and f.is_file()) or
                                          (self.allow_folders and f.is_dir())) and
                                          (self.match is None or self.match_re.search(f.name))):
                                      choices.append((f.path, f.name))
                              choices.sort(key=operator.itemgetter(1))
                  Severity: Major
                  Found in django/forms/fields.py - About 40 mins to fix

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

                        def to_python(self, value):
                    
                            def split_url(url):
                                """
                                Return a list of url parts via urlparse.urlsplit(), or raise
                    Severity: Minor
                    Found in django/forms/fields.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

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

                        def __init__(self, *, required=True, widget=None, label=None, initial=None,
                                     help_text='', error_messages=None, show_hidden_initial=False,
                                     validators=(), localize=False, disabled=False, label_suffix=None):
                            # required -- Boolean that specifies whether the field is required.
                            #             True by default.
                    Severity: Minor
                    Found in django/forms/fields.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