django/django

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

Summary

Maintainability
D
2 days
Test Coverage

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

import functools
import itertools
import operator
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 43 (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 6 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_queryset has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_prefetch_queryset(self, instances, queryset=None):
            if queryset is not None:
                raise ValueError("Custom queryset can't be used for this lookup.")
    
            # For efficiency, group the instances by content type and then do one
    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 __get__ has a Cognitive Complexity of 9 (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 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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, to, object_id_field='object_id', content_type_field='content_type',
    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__(self, field, to, related_name=None, related_query_name=None, limit_choices_to=None):
      Severity: Minor
      Found in django/contrib/contenttypes/fields.py - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status