django/django

View on GitHub
django/urls/resolvers.py

Summary

Maintainability
F
3 days
Test Coverage

File resolvers.py has 547 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 41 (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 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 _populate has a Cognitive Complexity of 31 (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 23 (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 3 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 _route_to_regex has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def _route_to_regex(route, is_endpoint=False):
        """
        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 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__(self, func, args, kwargs, url_name=None, app_names=None, namespaces=None, route=None):
    Severity: Major
    Found in django/urls/resolvers.py - About 50 mins to fix

      Avoid deeply nested control flow statements.
      Open

                                  for matches, pat, defaults, converters in url_pattern.reverse_dict.getlist(name):
                                      new_matches = normalize(p_pattern + pat)
                                      lookups.appendlist(
                                          name,
                                          (
      Severity: Major
      Found in django/urls/resolvers.py - About 45 mins to fix

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

            def _check_custom_error_handlers(self):
                messages = []
                # All handlers take (request, exception) arguments except handler500
                # which takes (request).
                for status_code, num_parameters in [(400, 2), (403, 2), (404, 2), (500, 1)]:
        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__(self, pattern, urlconf_name, default_kwargs=None, app_name=None, namespace=None):
        Severity: Minor
        Found in django/urls/resolvers.py - About 35 mins to fix

          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