netdata/netdata

View on GitHub
src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py

Summary

Maintainability
F
3 days
Test Coverage

File connectionpool.py has 622 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# SPDX-License-Identifier: MIT
from __future__ import absolute_import
import errno
import logging
import sys

    Function urlopen has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        def urlopen(self, method, url, body=None, headers=None, retries=None,
                    redirect=True, assert_same_host=True, timeout=_Default,
                    pool_timeout=None, release_conn=None, chunked=False,
                    body_pos=None, **response_kw):
            """

    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 19 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, host, port=None,

      Function _make_request has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def _make_request(self, conn, method, url, timeout=_Default, chunked=False,
                            **httplib_request_kw):
              """
              Perform a request on a given urllib connection object taken from our
              pool.

      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 urlopen has 13 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def urlopen(self, method, url, body=None, headers=None, retries=None,

        Function __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, host, port=None, strict=False,

          Function _get_conn has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def _get_conn(self, timeout=None):
                  """
                  Get a connection. Will return a pooled connection if one is available.
          
                  If no connections are available and :prop:`.block` is ``False``, then a
          Severity: Minor
          Found in src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py - About 55 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 _make_request has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _make_request(self, conn, method, url, timeout=_Default, chunked=False,
          Severity: Minor
          Found in src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py - About 45 mins to fix

            Avoid too many return statements within this function.
            Open

                    return response
            Severity: Major
            Found in src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return self.urlopen(
              Severity: Major
              Found in src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py - About 30 mins to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                            try:
                                retries = retries.increment(method, url, response=response, _pool=self)
                            except MaxRetryError:
                                if retries.raise_on_redirect:
                                    # Release the connection for this response, since we're not
                src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py on lines 710..718

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 43.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                            try:
                                retries = retries.increment(method, url, response=response, _pool=self)
                            except MaxRetryError:
                                if retries.raise_on_status:
                                    # Release the connection for this response, since we're not
                src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py on lines 687..695

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 43.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                            return self.urlopen(
                                method, url, body, headers,
                src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py on lines 699..700

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 36.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                            return self.urlopen(
                                method, redirect_location, body, headers,
                src/collectors/python.d.plugin/python_modules/urllib3/connectionpool.py on lines 721..722

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 36.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        if not isinstance(retries, Retry):
                            retries = Retry.from_int(retries, redirect=redirect, default=self.retries)
                src/collectors/python.d.plugin/python_modules/urllib3/contrib/appengine.py on lines 262..264

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 33.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status