netdata/netdata

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

Summary

Maintainability
F
6 days
Test Coverage

Function _syscall_wrapper has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
Open

    def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)

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 selectors.py has 448 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# SPDX-License-Identifier: MIT
# Backport of selectors.py from Python 3.5+ to support Python < 3.4
# Also has the behavior specified in PEP 475 which is to retry syscalls
# in the case of an EINTR error. This module is required because selectors34
# does not follow this behavior and instead returns that no dile descriptor

    Function select has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

            def select(self, timeout=None):
                if timeout is not None:
                    if timeout <= 0:
                        timeout = 0.0
                    else:

    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 select has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

            def select(self, timeout=None):
                if timeout is not None:
                    timeout = max(timeout, 0)
    
                max_events = len(self._fd_to_key) * 2

    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 select has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

            def select(self, timeout=None):
                # Selecting on empty lists on Windows errors out.
                if not len(self._readers) and not len(self._writers):
                    return []
    
    

    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 unregister has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def unregister(self, fileobj):
            """ Unregister a file object from being monitored. """
            try:
                key = self._fd_to_key.pop(self._fileobj_lookup(fileobj))
            except KeyError:

    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 select has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

            def select(self, timeout=None):
                ready = []
                fd_events = _syscall_wrapper(self._wrap_poll, True, timeout=timeout)
                for fd, event_mask in fd_events:
                    events = 0

    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 unregister has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

            def unregister(self, fileobj):
                key = super(KqueueSelector, self).unregister(fileobj)
                if key.events & EVENT_READ:
                    kevent = select.kevent(key.fd,
                                           select.KQ_FILTER_READ,

    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 recalc_timeout:
                                if "timeout" in kwargs:
                                    kwargs["timeout"] = expires - current_time
                        continue
    Severity: Major
    Found in src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if current_time > expires:
                                  raise OSError(errno=errno.ETIMEDOUT)
                              if recalc_timeout:
      Severity: Major
      Found in src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py - About 45 mins to fix

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

        def DefaultSelector():
            """ This function serves as a first call for DefaultSelector to
            detect if the select module is being monkey-patched incorrectly
            by eventlet, greenlet, and preserve proper behavior. """
            global _DEFAULT_SELECTOR
        Severity: Minor
        Found in src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.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 _wrap_poll has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def _wrap_poll(self, timeout=None):
                    """ Wrapper function for select.poll.poll() so that
                    _syscall_wrapper can work with only seconds. """
                    if timeout is not None:
                        if timeout <= 0:
        Severity: Minor
        Found in src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.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 _fileobj_lookup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def _fileobj_lookup(self, fileobj):
                """ Return a file descriptor from a file object.
                This wraps _fileobj_to_fd() to do an exhaustive
                search in case the object is invalid but we still
                have it in our map. Used by unregister() so we can
        Severity: Minor
        Found in src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.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

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

                    for fd, event_mask in fd_events:
                        events = 0
                        if event_mask & ~select.POLLIN:
                            events |= EVENT_WRITE
                        if event_mask & ~select.POLLOUT:
        src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py on lines 446..455

        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 95.

        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

                    for fd, event_mask in fd_events:
                        events = 0
                        if event_mask & ~select.EPOLLIN:
                            events |= EVENT_WRITE
                        if event_mask & ~select.EPOLLOUT:
        src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py on lines 382..391

        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 95.

        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

                    if key.events & EVENT_WRITE:
                        kevent = select.kevent(key.fd,
                                               select.KQ_FILTER_WRITE,
                                               select.KQ_EV_DELETE)
                        try:
        src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py on lines 493..499

        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 56.

        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

                    if key.events & EVENT_READ:
                        kevent = select.kevent(key.fd,
                                               select.KQ_FILTER_READ,
                                               select.KQ_EV_DELETE)
                        try:
        src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py on lines 501..507

        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 56.

        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

                    if events & EVENT_READ:
                        kevent = select.kevent(key.fd,
                                               select.KQ_FILTER_READ,
                                               select.KQ_EV_ADD)
        
        
        src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py on lines 482..487

        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 46.

        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

                    if events & EVENT_WRITE:
                        kevent = select.kevent(key.fd,
                                               select.KQ_FILTER_WRITE,
                                               select.KQ_EV_ADD)
        
        
        src/collectors/python.d.plugin/python_modules/urllib3/util/selectors.py on lines 475..480

        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 46.

        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