django/django

View on GitHub
django/contrib/contenttypes/fields.py

Summary

Maintainability
F
3 days
Test Coverage

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

import functools
import itertools
import warnings
from collections import defaultdict

Severity: Major
Found in django/contrib/contenttypes/fields.py - About 1 day to fix

    Function create_generic_related_manager has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_generic_related_manager(superclass, rel):
        """
        Factory function to create a manager that subclasses another manager
        (generally the default manager of a given model) and adds behaviors
        specific to generic relations.
    Severity: Minor
    Found in django/contrib/contenttypes/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 get_prefetch_querysets has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_prefetch_querysets(self, instances, querysets=None):
            custom_queryset_dict = {}
            if querysets is not None:
                for queryset in querysets:
                    ct_id = self.get_content_type(
    Severity: Minor
    Found in django/contrib/contenttypes/fields.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 __get__ has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def __get__(self, instance, cls=None):
            if instance is None:
                return self
    
            # Don't use getattr(instance, self.ct_field) here because that might
    Severity: Minor
    Found in django/contrib/contenttypes/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__(
    Severity: Major
    Found in django/contrib/contenttypes/fields.py - About 50 mins to fix

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

          def __init__(
      Severity: Minor
      Found in django/contrib/contenttypes/fields.py - About 35 mins to fix

        Avoid too many return statements within this function.
        Open

                    return await sync_to_async(self.update_or_create)(**kwargs)
        Severity: Major
        Found in django/contrib/contenttypes/fields.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return GenericRelatedObjectManager
          Severity: Major
          Found in django/contrib/contenttypes/fields.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return await sync_to_async(self.create)(**kwargs)
            Severity: Major
            Found in django/contrib/contenttypes/fields.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return await sync_to_async(self.get_or_create)(**kwargs)
              Severity: Major
              Found in django/contrib/contenttypes/fields.py - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status