django/django

View on GitHub
django/utils/translation/trans_real.py

Summary

Maintainability
C
1 day
Test Coverage

File trans_real.py has 398 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Translation helper functions."""
import functools
import gettext as gettext_module
import os
import re
Severity: Minor
Found in django/utils/translation/trans_real.py - About 5 hrs to fix

    Function get_supported_language_variant has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_supported_language_variant(lang_code, strict=False):
        """
        Return the language code that's listed in supported languages, possibly
        selecting a more generic variant. Raise LookupError if nothing is found.
    
    
    Severity: Minor
    Found in django/utils/translation/trans_real.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_language_from_request has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_language_from_request(request, check_path=False):
        """
        Analyze the request to find what language the user wants the system to
        show. Only languages listed in settings.LANGUAGES are taken into account.
        If the user requests a sublanguage where we have a main language, we send
    Severity: Minor
    Found in django/utils/translation/trans_real.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 a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, language, domain=None, localedirs=None):
            """Create a GNUTranslations() using many locale directories"""
            gettext_module.GNUTranslations.__init__(self)
            if domain is not None:
                self.domain = domain
    Severity: Minor
    Found in django/utils/translation/trans_real.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 parse_accept_lang_header has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_accept_lang_header(lang_string):
        """
        Parse the lang_string, which is the body of an HTTP Accept-Language
        header, and return a tuple of (lang, q-value), ordered by 'q' values.
    
    
    Severity: Minor
    Found in django/utils/translation/trans_real.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 settings.LANGUAGE_CODE
    Severity: Major
    Found in django/utils/translation/trans_real.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return get_supported_language_variant(settings.LANGUAGE_CODE)
      Severity: Major
      Found in django/utils/translation/trans_real.py - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status