django/django

View on GitHub
django/db/backends/sqlite3/_functions.py

Summary

Maintainability
D
1 day
Test Coverage

File _functions.py has 404 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Implementations of SQL functions for SQLite.
"""

import functools
Severity: Minor
Found in django/db/backends/sqlite3/_functions.py - About 5 hrs to fix

    Function register has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def register(connection):
        create_deterministic_function = functools.partial(
            connection.create_function,
            deterministic=True,
        )
    Severity: Minor
    Found in django/db/backends/sqlite3/_functions.py - About 1 hr to fix

      Function _sqlite_datetime_parse has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def _sqlite_datetime_parse(dt, tzname=None, conn_tzname=None):
          if dt is None:
              return None
          try:
              dt = typecast_timestamp(dt)
      Severity: Minor
      Found in django/db/backends/sqlite3/_functions.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 _sqlite_time_trunc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def _sqlite_time_trunc(lookup_type, dt, tzname, conn_tzname):
          if dt is None:
              return None
          dt_parsed = _sqlite_datetime_parse(dt, tzname, conn_tzname)
          if dt_parsed is None:
      Severity: Minor
      Found in django/db/backends/sqlite3/_functions.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 _sqlite_datetime_trunc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def _sqlite_datetime_trunc(lookup_type, dt, tzname, conn_tzname):
          dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)
          if dt is None:
              return None
          if lookup_type == "year":
      Severity: Minor
      Found in django/db/backends/sqlite3/_functions.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 _sqlite_datetime_extract has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def _sqlite_datetime_extract(lookup_type, dt, tzname=None, conn_tzname=None):
          dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)
          if dt is None:
              return None
          if lookup_type == "week_day":
      Severity: Minor
      Found in django/db/backends/sqlite3/_functions.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

      Avoid too many return statements within this function.
      Open

              return f"{dt.year:04d}-{dt.month:02d}-{dt.day:02d}"
      Severity: Major
      Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return ceil(dt.month / 3)
        Severity: Major
        Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return f"{dt.year:04d}-{dt.month:02d}-{dt.day:02d} {dt.hour:02d}:00:00"
          Severity: Major
          Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return dt.isocalendar().year
            Severity: Major
            Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return f"{dt.year:04d}-{dt.month:02d}-{dt.day:02d} 00:00:00"
              Severity: Major
              Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return f"{dt.hour:02d}:{dt.minute:02d}:{dt.second:02d}"
                Severity: Major
                Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return f"{dt.year:04d}-{dt.month:02d}-{dt.day:02d} 00:00:00"
                  Severity: Major
                  Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return getattr(dt, lookup_type)
                    Severity: Major
                    Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return (
                      Severity: Major
                      Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return f"{dt.year:04d}-{dt.month:02d}-{dt.day:02d}"
                        Severity: Major
                        Found in django/db/backends/sqlite3/_functions.py - About 30 mins to fix

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

                          def _sqlite_date_trunc(lookup_type, dt, tzname, conn_tzname):
                              dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)
                              if dt is None:
                                  return None
                              if lookup_type == "year":
                          Severity: Minor
                          Found in django/db/backends/sqlite3/_functions.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