kennethreitz/requests

View on GitHub
src/requests/models.py

Summary

Maintainability
F
4 days
Test Coverage

File models.py has 737 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
requests.models
~~~~~~~~~~~~~~~

This module contains the primary objects that power Requests.
Severity: Major
Found in src/requests/models.py - About 1 day to fix

    Function _encode_files has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        def _encode_files(files, data):
            """Build the body for a multipart/form-data request.
    
            Will successfully encode files when passed as a dict or a list of
            tuples. Order is retained if data is a list of tuples but arbitrary
    Severity: Minor
    Found in src/requests/models.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

    Function prepare_body has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        def prepare_body(self, data, files, json=None):
            """Prepares the given HTTP body data."""
    
            # Check if file, fo, generator, iterator.
            # If not, run through normal process.
    Severity: Minor
    Found in src/requests/models.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

    Function _encode_params has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        def _encode_params(data):
            """Encode parameters in a piece of data.
    
            Will successfully encode parameters when passed as a dict or a list of
            2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
    Severity: Minor
    Found in src/requests/models.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 iter_content has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def iter_content(self, chunk_size=1, decode_unicode=False):
            """Iterates over the response data.  When stream=True is set on the
            request, this avoids reading the content at once into memory for
            large responses.  The chunk size is the number of bytes it should
            read into memory.  This is not necessarily the length of each item
    Severity: Minor
    Found in src/requests/models.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 prepare has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def prepare(
    Severity: Major
    Found in src/requests/models.py - About 1 hr to fix

      Function json has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def json(self, **kwargs):
              r"""Returns the json-encoded content of a response, if any.
      
              :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
              :raises requests.exceptions.JSONDecodeError: If the response body does not
      Severity: Minor
      Found in src/requests/models.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 10 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(
      Severity: Major
      Found in src/requests/models.py - About 1 hr to fix

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

            def iter_lines(
                self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=False, delimiter=None
            ):
                """Iterates over the response data, one line at a time.  When
                stream=True is set on the request, this avoids reading the
        Severity: Minor
        Found in src/requests/models.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 raise_for_status has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def raise_for_status(self):
                """Raises :class:`HTTPError`, if one occurred."""
        
                http_error_msg = ""
                if isinstance(self.reason, bytes):
        Severity: Minor
        Found in src/requests/models.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

        Function content has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def content(self):
                """Content of the response, in bytes."""
        
                if self._content is False:
                    # Read the contents.
        Severity: Minor
        Found in src/requests/models.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

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

            def prepare_auth(self, auth, url=""):
                """Prepares the given HTTP auth data."""
        
                # If no Auth is explicitly provided, extract it from the URL first.
                if auth is None:
        Severity: Minor
        Found in src/requests/models.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 prepare_url has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def prepare_url(self, url, params):
                """Prepares the given HTTP URL."""
                #: Accept objects that have string representations.
                #: We're unable to blindly call unicode/str functions
                #: as this will include the bytestring indicator (b'')
        Severity: Minor
        Found in src/requests/models.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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(
                self,
                method=None,
                url=None,
                headers=None,
        Severity: Minor
        Found in src/requests/models.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