django/django

View on GitHub
django/db/models/fields/__init__.py

Summary

Maintainability
F
1 wk
Test Coverage

File __init__.py has 1974 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import collections.abc
import copy
import datetime
import decimal
import operator
Severity: Major
Found in django/db/models/fields/__init__.py - About 5 days to fix

    Field has 60 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Field(RegisterLookupMixin):
        """Base class for all field types"""
    
        # Designates whether empty strings fundamentally are allowed at the
        # database level.
    Severity: Major
    Found in django/db/models/fields/__init__.py - About 1 day to fix

      Function _check_choices has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_choices(self):
              if not self.choices:
                  return []
      
              if not is_iterable(self.choices) or isinstance(self.choices, str):
      Severity: Minor
      Found in django/db/models/fields/__init__.py - About 3 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 __init__ has 22 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, verbose_name=None, name=None, primary_key=False,
      Severity: Major
      Found in django/db/models/fields/__init__.py - About 2 hrs to fix

        Function validate has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate(self, value, model_instance):
                """
                Validate value and raise ValidationError if necessary. Subclasses
                should override this to provide validation logic.
                """
        Severity: Minor
        Found in django/db/models/fields/__init__.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 formfield has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            def formfield(self, form_class=None, choices_form_class=None, **kwargs):
                """Return a django.forms.Field instance for this field."""
                defaults = {
                    'required': not self.blank,
                    'label': capfirst(self.verbose_name),
        Severity: Minor
        Found in django/db/models/fields/__init__.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 deconstruct has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def deconstruct(self):
                """
                Return enough information to recreate the field as a 4-tuple:
        
                 * The name of the field on the model, if contribute_to_class() has
        Severity: Minor
        Found in django/db/models/fields/__init__.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 validators has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def validators(self):
                # These validators can't be added at field initialization time since
                # they're based on values retrieved from `connection`.
                validators_ = super().validators
                internal_type = self.get_internal_type()
        Severity: Minor
        Found in django/db/models/fields/__init__.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 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def __init__(self, verbose_name=None, name=None, primary_key=False,
                         max_length=None, unique=False, blank=False, null=False,
                         db_index=False, rel=None, default=NOT_PROVIDED, editable=True,
                         serialize=True, unique_for_date=None, unique_for_month=None,
                         unique_for_year=None, choices=None, help_text='', db_column=None,
        Severity: Minor
        Found in django/db/models/fields/__init__.py - About 1 hr to fix

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

              def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_choices_to=None, ordering=()):
                  """
                  Return choices with a default blank choices included, for use
                  as <select> choices for this field.
                  """
          Severity: Minor
          Found in django/db/models/fields/__init__.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 _check_fix_default_value has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def _check_fix_default_value(self):
                  """
                  Warn that using an actual date or datetime value is probably wrong;
                  it's only evaluated on server startup.
                  """
          Severity: Minor
          Found in django/db/models/fields/__init__.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 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, verbose_name=None, name=None, path='', match=None,
          Severity: Major
          Found in django/db/models/fields/__init__.py - About 1 hr to fix

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

                def to_python(self, value):
                    if value is None:
                        return value
                    if isinstance(value, datetime.datetime):
                        return value
            Severity: Minor
            Found in django/db/models/fields/__init__.py - About 55 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_fix_default_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def _check_fix_default_value(self):
                    """
                    Warn that using an actual date or datetime value is probably wrong;
                    it's only evaluated on server startup.
                    """
            Severity: Minor
            Found in django/db/models/fields/__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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __init__(self, verbose_name=None, name=None, protocol='both',
            Severity: Minor
            Found in django/db/models/fields/__init__.py - About 45 mins to fix

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

                  def _check_fix_default_value(self):
                      """
                      Warn that using an actual date or datetime value is probably wrong;
                      it's only evaluated on server startup.
                      """
              Severity: Minor
              Found in django/db/models/fields/__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

              Avoid deeply nested control flow statements.
              Open

                                      if value == optgroup_key:
                                          return
                              elif value == option_key:
              Severity: Major
              Found in django/db/models/fields/__init__.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 = []
                Severity: Minor
                Found in django/db/models/fields/__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 to_python has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def to_python(self, value):
                        if value is None:
                            return value
                        if isinstance(value, datetime.datetime):
                            if settings.USE_TZ and timezone.is_aware(value):
                Severity: Minor
                Found in django/db/models/fields/__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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def __init__(self, verbose_name=None, name=None, auto_now=False,
                Severity: Minor
                Found in django/db/models/fields/__init__.py - About 35 mins to fix

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

                      def __init__(self, verbose_name=None, name=None, auto_now=False,
                  Severity: Minor
                  Found in django/db/models/fields/__init__.py - About 35 mins to fix

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

                        def __init__(self, *args, max_length=50, db_index=True, allow_unicode=False, **kwargs):
                    Severity: Minor
                    Found in django/db/models/fields/__init__.py - About 35 mins to fix

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

                          def __init__(self, verbose_name=None, name=None, max_digits=None,
                      Severity: Minor
                      Found in django/db/models/fields/__init__.py - About 35 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return [
                        Severity: Major
                        Found in django/db/models/fields/__init__.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                          return datetime.datetime(parsed.year, parsed.month, parsed.day)
                          Severity: Major
                          Found in django/db/models/fields/__init__.py - About 30 mins to fix

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

                                def deconstruct(self):
                                    name, path, args, kwargs = super().deconstruct()
                                    if self.path != '':
                                        kwargs['path'] = self.path
                                    if self.match is not None:
                            Severity: Minor
                            Found in django/db/models/fields/__init__.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

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

                                def to_python(self, value):
                                    if self.null and value in self.empty_values:
                                        return None
                                    if value in (True, False):
                                        # 1/0 are equal to True/False. bool() converts former to latter.
                            Severity: Minor
                            Found in django/db/models/fields/__init__.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

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

                                def contribute_to_class(self, cls, name, private_only=False):
                                    """
                                    Register the field with the model class it belongs to.
                            
                                    If private_only is True, create a separate instance of this field
                            Severity: Minor
                            Found in django/db/models/fields/__init__.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