MediaMath/t1-python

View on GitHub
terminalone/service.py

Summary

Maintainability
D
2 days
Test Coverage

File service.py has 442 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
"""Provides service object for T1."""

from __future__ import absolute_import, division
from collections import Iterator
Severity: Minor
Found in terminalone/service.py - About 6 hrs to fix

    Cyclomatic complexity is too high in method get. (11)
    Open

        def get(self,
                collection,
                entity=None,
                child=None,
                limit=None,
    Severity: Minor
    Found in terminalone/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

    Cyclomatic complexity is too high in method _construct_url. (9)
    Open

        @staticmethod
        def _construct_url(collection, entity, child, limit):
            """Construct URL."""
            url = [collection, ]
            if entity is not None:
    Severity: Minor
    Found in terminalone/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

    Cyclomatic complexity is too high in method _construct_params. (9)
    Open

        @staticmethod
        def _construct_params(entity, **kwargs):
            """Construct URL params."""
            if entity is not None:
                params = {}
    Severity: Minor
    Found in terminalone/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

    Cyclomatic complexity is too high in method authenticate. (8)
    Open

        def authenticate(self, auth_method, **kwargs):
            """Authenticate using method given."""
            session_id = kwargs.get('session_id')
            access_token = kwargs.get('access_token')
            if session_id is not None and auth_method in ['cookie',
    Severity: Minor
    Found in terminalone/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

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

        def __init__(self,
    Severity: Major
    Found in terminalone/service.py - About 2 hrs to fix

      Function get has 16 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def get(self,
      Severity: Major
      Found in terminalone/service.py - About 2 hrs to fix

        Cyclomatic complexity is too high in method _return_class. (7)
        Open

            def _return_class(self, ent_dict,
                              child=None, child_id=None,
                              entity_id=None, collection=None):
                """Generate item for new class instantiation."""
                ent_type = ent_dict.get('_type', ent_dict.get('type'))
        Severity: Minor
        Found in terminalone/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

        Function _construct_url has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def _construct_url(collection, entity, child, limit):
                """Construct URL."""
                url = [collection, ]
                if entity is not None:
                    url.append(str(entity))  # str so that we can use join
        Severity: Minor
        Found in terminalone/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 _construct_params has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def _construct_params(entity, **kwargs):
                """Construct URL params."""
                if entity is not None:
                    params = {}
                else:
        Severity: Minor
        Found in terminalone/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

        Cyclomatic complexity is too high in method new. (6)
        Open

            def new(self, collection, report=None, properties=None, version=None, *args, **kwargs):
                """Return a fresh class instance for a new entity.
        
                ac = t1.new('atomic_creative') OR
                ac = t1.new('atomic_creatives') OR even
        Severity: Minor
        Found in terminalone/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

        Cyclomatic complexity is too high in class T1. (6)
        Open

        class T1(Connection):
            """Service class for ALL other T1 entities, e.g.: t1 = T1(auth).
        
            Accepts authentication parameters. Supports get methods to get
            collections or an entity, find method to user inner-join-like queries.
        Severity: Minor
        Found in terminalone/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

        Cyclomatic complexity is too high in method __init__. (6)
        Open

            def __init__(self,
                         username=None,
                         password=None,
                         api_key=None,
                         client_id=None,
        Severity: Minor
        Found in terminalone/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

        Cyclomatic complexity is too high in method _get_all. (6)
        Open

            def _get_all(self, collection, **kwargs):
                """Construct iterator to get all entities in a collection.
        
                Pages over 100 entities.
                This method should not be called directly: it's called from T1.get.
        Severity: Minor
        Found in terminalone/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

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

            def _return_class(self, ent_dict,
                              child=None, child_id=None,
                              entity_id=None, collection=None):
                """Generate item for new class instantiation."""
                ent_type = ent_dict.get('_type', ent_dict.get('type'))
        Severity: Minor
        Found in terminalone/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 get has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get(self,
                    collection,
                    entity=None,
                    child=None,
                    limit=None,
        Severity: Minor
        Found in terminalone/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 _detect_auth_method has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def _detect_auth_method(username, password, session_id,
        Severity: Major
        Found in terminalone/service.py - About 50 mins to fix

          Function new has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def new(self, collection, report=None, properties=None, version=None, *args, **kwargs):
          Severity: Minor
          Found in terminalone/service.py - About 45 mins to fix

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

                def find(self, collection, variable, operator, candidates, **kwargs):
            Severity: Minor
            Found in terminalone/service.py - About 35 mins to fix

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

                  def _return_class(self, ent_dict,
              Severity: Minor
              Found in terminalone/service.py - About 35 mins to fix

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

                    def _gen_classes(self, entities, child, child_id, entity_id, collection):
                Severity: Minor
                Found in terminalone/service.py - About 35 mins to fix

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

                      def _get_all(self, collection, **kwargs):
                          """Construct iterator to get all entities in a collection.
                  
                          Pages over 100 entities.
                          This method should not be called directly: it's called from T1.get.
                  Severity: Minor
                  Found in terminalone/service.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

                  Avoid too many return statements within this function.
                  Open

                              return ent_gen
                  Severity: Major
                  Found in terminalone/service.py - About 30 mins to fix

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

                        def authenticate(self, auth_method, **kwargs):
                            """Authenticate using method given."""
                            session_id = kwargs.get('session_id')
                            access_token = kwargs.get('access_token')
                            if session_id is not None and auth_method in ['cookie',
                    Severity: Minor
                    Found in terminalone/service.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 new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def new(self, collection, report=None, properties=None, version=None, *args, **kwargs):
                            """Return a fresh class instance for a new entity.
                    
                            ac = t1.new('atomic_creative') OR
                            ac = t1.new('atomic_creatives') OR even
                    Severity: Minor
                    Found in terminalone/service.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