Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cohesion does not produce the same results with debug on and off #12

Closed
mschwager opened this issue Jul 9, 2019 · 0 comments
Closed

Comments

@mschwager
Copy link
Owner

For example:

$ cat example.py 
class ExampleClass1(object):
    class_variable1 = 5
    class_variable2 = 6

    def func1(self):
        self.instance_variable = 6

        def inner_func(b):
            return b + 5

        local_variable = self.class_variable1

        return local_variable

    def func2(self):
        print(self.class_variable2)

    @staticmethod
    def func3(variable):
        return variable + 7

class ExampleClass2(object):
    def func1(self):
        self.instance_variable1 = 7

Without the --debug flag:

$ PYTHONPATH=lib/ python -m cohesion -f example.py 
File: example.py
  Class: ExampleClass2 (22:0)
    Function: func1 1/1 100.00%
    Total: 100.00%
  Class: ExampleClass1 (1:0)
    Function: func3 staticmethod
    Function: func2 1/3 33.33%
    Function: func1 2/3 66.67%
    Total: 33.33%

With the --debug flag:

$ PYTHONPATH=lib/ python -m cohesion --debug -f example.py 
{
    "ExampleClass2": {
        "cohesion": null,
        "variables": [
            "instance_variable1"
        ],
        "lineno": 22,
        "col_offset": 0,
        "functions": {
            "func1": {
                "classmethod": false,
                "variables": [
                    "instance_variable1"
                ],
                "bounded": true,
                "staticmethod": false
            }
        }
    },
    "ExampleClass1": {
        "cohesion": null,
        "variables": [
            "class_variable2",
            "class_variable1",
            "instance_variable"
        ],
        "lineno": 1,
        "col_offset": 0,
        "functions": {
            "func3": {
                "classmethod": false,
                "variables": [],
                "bounded": false,
                "staticmethod": true
            },
            "func2": {
                "classmethod": false,
                "variables": [
                    "class_variable2"
                ],
                "bounded": true,
                "staticmethod": false
            },
            "func1": {
                "classmethod": false,
                "variables": [
                    "class_variable1",
                    "instance_variable"
                ],
                "bounded": true,
                "staticmethod": false
            }
        }
    }
}

Notice the cohesion value is null with debugging turned on. It looks like this value is calculated differently depending on if debugging is turned on. We should remedy this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant