Orange-OpenSource/python-onapsdk

View on GitHub
src/onapsdk/onap_service.py

Summary

Maintainability
B
5 hrs
Test Coverage
A
98%

Cyclomatic complexity is too high in method send_message. (12)
Open

    @classmethod
    def send_message(cls, method: str, action: str, url: str,  # pylint: disable=too-many-locals
                     **kwargs) -> Union[requests.Response, None]:
        """
        Send a message to an ONAP service.
Severity: Minor
Found in src/onapsdk/onap_service.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

File onap_service.py has 252 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: Apache-2.0
"""ONAP Service module."""
from abc import ABC
Severity: Minor
Found in src/onapsdk/onap_service.py - About 2 hrs to fix

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

        def send_message(cls, method: str, action: str, url: str,  # pylint: disable=too-many-locals
                         **kwargs) -> Union[requests.Response, None]:
            """
            Send a message to an ONAP service.
    
    
    Severity: Minor
    Found in src/onapsdk/onap_service.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 send_message has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def send_message(cls, method: str, action: str, url: str,  # pylint: disable=too-many-locals
    Severity: Minor
    Found in src/onapsdk/onap_service.py - About 45 mins to fix

      Function send_message_json has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def send_message_json(cls, method: str, action: str, url: str,
      Severity: Minor
      Found in src/onapsdk/onap_service.py - About 35 mins to fix

        Continuation line over-indented for visual indent
        Open

                                              ["application/json", "text/plain"]) else "n/a")
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Continuation lines indentation.

        Continuation lines should align wrapped elements either vertically
        using Python's implicit line joining inside parentheses, brackets
        and braces, or using a hanging indent.
        
        When using a hanging indent these considerations should be applied:
        - there should be no arguments on the first line, and
        - further indentation should be used to clearly distinguish itself
          as a continuation line.
        
        Okay: a = (\n)
        E123: a = (\n    )
        
        Okay: a = (\n    42)
        E121: a = (\n   42)
        E122: a = (\n42)
        E123: a = (\n    42\n    )
        E124: a = (24,\n     42\n)
        E125: if (\n    b):\n    pass
        E126: a = (\n        42)
        E127: a = (24,\n      42)
        E128: a = (24,\n    42)
        E129: if (a or\n    b):\n    pass
        E131: a = (\n    42\n 24)

        Line too long (86 > 79 characters)
        Open

                Add _logger property for any OnapService with it's class name as a logger name
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (85 > 79 characters)
        Open

            def set_header(header: Optional[Union[Dict[str, Any], Callable]] = None) -> None:
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (96 > 79 characters)
        Open

            def send_message(cls, method: str, action: str, url: str,  # pylint: disable=too-many-locals
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (89 > 79 characters)
        Open

                      creation. Could be useful if you need to connect with ONAP through some API
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (83 > 79 characters)
        Open

                    * callable - a method which is going to be called every time on request
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (84 > 79 characters)
        Open

                    OnapService.permanent_headers = OnapService.PermanentHeadersCollection()
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (85 > 79 characters)
        Open

                    msg = f'Code: {cause.response.status_code}. Info: {cause.response.text}.'
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (92 > 79 characters)
        Open

                      gateway and you need to take care about authentication. The callable shouldn't
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (85 > 79 characters)
        Open

                                              ["application/json", "text/plain"]) else "n/a")
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        The backslash is redundant between brackets
        Open

                                          response.headers.get("Content-Type", "") in \
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Avoid explicit line join between brackets.

        The preferred way of wrapping long lines is by using Python's
        implied line continuation inside parentheses, brackets and braces.
        Long lines can be broken over multiple lines by wrapping expressions
        in parentheses.  These should be used in preference to using a
        backslash for line continuation.
        
        E502: aaa = [123, \\n       123]
        E502: aaa = ("bbb " \\n       "ccc")
        
        Okay: aaa = [123,\n       123]
        Okay: aaa = ("bbb "\n       "ccc")
        Okay: aaa = "bbb " \\n    "ccc"
        Okay: aaa = 123  # \\

        Line too long (80 > 79 characters)
        Open

            permanent_headers: PermanentHeadersCollection = PermanentHeadersCollection()
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        Line too long (95 > 79 characters)
        Open

                    header (Optional[Union[Dict[str, Any], Callable]]): header to set. Defaults to None
        Severity: Minor
        Found in src/onapsdk/onap_service.py by pep8

        Limit all lines to a maximum of 79 characters.

        There are still many devices around that are limited to 80 character
        lines; plus, limiting windows to 80 characters makes it possible to
        have several windows side-by-side.  The default wrapping on such
        devices looks ugly.  Therefore, please limit all lines to a maximum
        of 79 characters. For flowing long blocks of text (docstrings or
        comments), limiting the length to 72 characters is recommended.
        
        Reports error E501.

        There are no issues that match your filters.

        Category
        Status