django/django

View on GitHub
django/urls/resolvers.py

Summary

Maintainability
F
4 days
Test Coverage

File resolvers.py has 693 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
This module converts requested URLs to callback view functions.

URLResolver is the main class here. Its resolve() method takes a URL (as
a string) and returns a ResolverMatch object which provides access to all
Severity: Major
Found in django/urls/resolvers.py - About 1 day to fix

    Function _reverse_with_prefix has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
    Open

        def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
            if args and kwargs:
                raise ValueError("Don't mix *args and **kwargs in call to reverse()!")
    
            if not self._populated:
    Severity: Minor
    Found in django/urls/resolvers.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 _populate has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        def _populate(self):
            # Short-circuit if called recursively in this thread to prevent
            # infinite recursion. Concurrent threads may call this at the same
            # time and will need to continue, so set 'populating' on a
            # thread-local variable.
    Severity: Minor
    Found in django/urls/resolvers.py - About 4 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 resolve has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def resolve(self, path):
            path = str(path)  # path may be a reverse_lazy object
            tried = []
            match = self.pattern.match(path)
            if match:
    Severity: Minor
    Found in django/urls/resolvers.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 __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Major
    Found in django/urls/resolvers.py - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                                  for (
                                      matches,
                                      pat,
                                      defaults,
                                      converters,
      Severity: Major
      Found in django/urls/resolvers.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if kwargs.get(k, v) != v:
                                    matches = False
                                    break
                            if not matches:
        Severity: Major
        Found in django/urls/resolvers.py - About 45 mins to fix

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

          def _route_to_regex(route, is_endpoint):
              """
              Convert a path pattern into a regular expression. Return the regular
              expression and a dictionary mapping the capture names to the converters.
              For example, 'foo/<int:pk>' returns '^foo\\/(?P<pk>[0-9]+)'
          Severity: Minor
          Found in django/urls/resolvers.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

                                  if k in params:
                                      continue
                                  if kwargs.get(k, v) != v:
          Severity: Major
          Found in django/urls/resolvers.py - About 45 mins to fix

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

                def _check_pattern_unmatched_angle_brackets(self):
                    warnings = []
                    msg = "Your URL pattern %s has an unmatched '%s' bracket."
                    brackets = re.findall(r"[<>]", str(self._route))
                    open_bracket_counter = 0
            Severity: Minor
            Found in django/urls/resolvers.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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __init__(
            Severity: Minor
            Found in django/urls/resolvers.py - About 35 mins to fix

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

                  def __init__(
                      self,
                      func,
                      args,
                      kwargs,
              Severity: Minor
              Found in django/urls/resolvers.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

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

                  def match(self, path):
                      match = self.regex.search(path)
                      if match:
                          # RoutePattern doesn't allow non-named groups so args are ignored.
                          kwargs = match.groupdict()
              Severity: Minor
              Found in django/urls/resolvers.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