rohanpm/pidiff

View on GitHub
pidiff/_impl/diff/diff.py

Summary

Maintainability
C
1 day
Test Coverage

File diff.py has 406 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
import functools
from typing import Optional, Set

import semver  # type: ignore
Severity: Minor
Found in pidiff/_impl/diff/diff.py - About 5 hrs to fix

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

        def diff_positional_args(self, sym_old, sym_new):
            sig_old = sym_old.ob.signature
            sig_new = sym_new.ob.signature
    
            old_arg_names = sig_old.positional_args
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 diff has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def diff(
        api_old: dict, api_new: dict, options: Optional[DiffOptions] = None
    ) -> DiffResult:
        """Perform a diff between two interfaces.
    
    
    Severity: Minor
    Found in pidiff/_impl/diff/diff.py - About 45 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 summarize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def summarize(ctx, log, new_version):
        LOG.info("")
        LOG.info("---------------------------------------------------------------------")
    
        if log.max_change_type == ChangeType.NONE:
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 is_enabled has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def is_enabled(self, code):
            enabled = self.options.enabled
            disabled = self.options.disabled
    
            for name in (code.errcode, code.errname):
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 max_change_allowed has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def max_change_allowed(self):
            old_vinfo = self.old_version_info
            new_vinfo = self.new_version_info
    
            # default applies if any version is unavailable/incomparable
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 diff_named_args has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def diff_named_args(self, sym_old, sym_new):
            sig_old = sym_old.ob.signature
            sig_new = sym_new.ob.signature
    
            old_arg_names = sig_old.named_kwargs
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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

    Either merge this branch with the identical one on line "212" or change one of the implementations.
    Open

                    out = ChangeType.MAJOR
    Severity: Major
    Found in pidiff/_impl/diff/diff.py by sonar-python

    Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

    Noncompliant Code Example

    if 0 <= a < 10:
        do_the_thing()
    elif 10 <= a < 20:
        do_the_other_thing()
    elif 20 <= a < 50:
        do_the_thing()  # Noncompliant; duplicates first condition
    else:
        do_the_rest()
    
    b = 4 if a > 12 else 4
    

    Compliant Solution

    if (0 <= a < 10) or (20 <= a < 50):
        do_the_thing()
    elif 10 <= a < 20:
        do_the_other_thing()
    else:
        do_the_rest()
    
    b = 4
    

    or

    if 0 <= a < 10:
        do_the_thing()
    elif 10 <= a < 20:
        do_the_other_thing()
    elif 20 <= a < 50:
        do_the_third_thing()
    else:
        do_the_rest()
    
    b = 8 if a > 12 else 4
    

    Line too long (82 > 79 characters)
    Open

        return DiffResult(log.max_change_type, differ.max_change_allowed, new_version)
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 (80 > 79 characters)
    Open

                if not sig_old.has_default_for(old_arg) and sig_new.has_default_for(
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 (87 > 79 characters)
    Open

                self.AddedOptionalArg(sym_old, sym_new, arg_name=", ".join(added_optional))
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 (80 > 79 characters)
    Open

                self.AddedArg(sym_old, sym_new, arg_name=", ".join(added_mandatory))
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 (88 > 79 characters)
    Open

                    new_vinfo.major == old_vinfo.major and new_vinfo.minor > old_vinfo.minor
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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 (80 > 79 characters)
    Open

            LOG.error("New version should be equal or greater than %s", new_version)
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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

        LOG.info("---------------------------------------------------------------------")
    Severity: Minor
    Found in pidiff/_impl/diff/diff.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