django/django

View on GitHub
django/utils/regex_helper.py

Summary

Maintainability
D
3 days
Test Coverage

Function normalize has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
Open

def normalize(pattern):
    r"""
    Given a reg-exp pattern, normalize it to an iterable of forms that
    suffice for reverse matching. This does the following:

Severity: Minor
Found in django/utils/regex_helper.py - About 1 day 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 flatten_result has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

def flatten_result(source):
    """
    Turn the given source sequence into a list of reg-exp possibilities and
    their arguments. Return a list of strings and a list of argument lists.
    Each of the two lists will be of the same length.
Severity: Minor
Found in django/utils/regex_helper.py - About 5 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

File regex_helper.py has 273 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Functions for reversing a regular expression (used in reverse URL resolving).
Used internally by Django and not intended for external use.

This is not, and is not intended to be, a complete reg-exp decompiler. It
Severity: Minor
Found in django/utils/regex_helper.py - About 2 hrs to fix

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

    def get_quantifier(ch, input_iter):
        """
        Parse a quantifier from the input, where "ch" is the first character in the
        quantifier.
    
    
    Severity: Minor
    Found in django/utils/regex_helper.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 walk_to_end has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def walk_to_end(ch, input_iter):
        """
        The iterator is currently inside a capturing group. Walk to the close of
        this group, skipping over any nested groups and handling escaped
        parentheses correctly.
    Severity: Minor
    Found in django/utils/regex_helper.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

    Avoid deeply nested control flow statements.
    Open

                            if ch == "<":
                                terminal_char = ">"
                            # We are in a named backreference.
                            else:
                                terminal_char = ")"
    Severity: Major
    Found in django/utils/regex_helper.py - About 45 mins to fix

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

      def contains(source, inst):
          """
          Return True if the "source" contains an instance of "inst". False,
          otherwise.
          """
      Severity: Minor
      Found in django/utils/regex_helper.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

                              while ch != terminal_char:
                                  name.append(ch)
                                  ch, escaped = next(pattern_iter)
                              param = "".join(name)
      Severity: Major
      Found in django/utils/regex_helper.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if terminal_char != ")":
                                    result.append(Group((("%%(%s)s" % param), param)))
                                    walk_to_end(ch, pattern_iter)
                                else:
                                    result.append(Group((("%%(%s)s" % param), None)))
        Severity: Major
        Found in django/utils/regex_helper.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if ch not in ("<", "="):
                                      raise ValueError(
                                          "Non-reversible reg-exp portion: '(?P%s'" % ch
                                      )
                                  # We are in a named capturing group. Extra the name and
          Severity: Major
          Found in django/utils/regex_helper.py - About 45 mins to fix

            There are no issues that match your filters.

            Category
            Status