SylvainDe/DidYouMean-Python

View on GitHub
didyoumean/didyoumean_internal.py

Summary

Maintainability
F
3 days
Test Coverage

File didyoumean_internal.py has 749 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8
"""Logic to add suggestions to exceptions."""
import keyword
import difflib
import didyoumean_re as re
Severity: Major
Found in didyoumean/didyoumean_internal.py - About 1 day to fix

    Function suggest_attribute_alternative has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

    def suggest_attribute_alternative(attribute, type_str, attributes):
        """Suggest alternative to the non-found attribute."""
        for s in suggest_attribute_synonyms(attribute, attributes):
            yield s
        is_iterable = '__iter__' in attributes or \
    Severity: Minor
    Found in didyoumean/didyoumean_internal.py - About 5 hrs 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 add_string_to_exception has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def add_string_to_exception(value, string):
        """Add string to the exception parameter."""
        # The point is to have the string visible when the exception is printed
        # or converted to string - may it be via `str()`, `repr()` or when the
        # exception is uncaught and displayed (which seems to use `str()`).
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 suggest_name_as_attribute has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def suggest_name_as_attribute(name, objdict):
        """Suggest that name could be an attribute of an object.
    
        Example: 'do_stuff()' -> 'self.do_stuff()'.
        """
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 suggest_unsupported_op has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def suggest_unsupported_op(value, frame, groups):
        """Get suggestions for UNSUPPORTED_OP_RE/UNSUPPORTED_OP_SUGG_RE."""
        del value  # unused param
        binary, type1, type2 = groups[:3]
        sugg = "" if len(groups) < 3 + 1 else groups[3]
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 suggest_nb_arg has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def suggest_nb_arg(value, frame, groups):
        """Get suggestions in case of NB ARGUMENT error."""
        del value  # unused param
        func_name, expected, given = groups
        given_nb = int(given)
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 suggest_attribute_is_other_obj has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def suggest_attribute_is_other_obj(attribute, type_str, frame):
        """Suggest that attribute correspond to another object.
    
        This can happen in two cases:
         - A misused builtin function
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 suggest_invalid_syntax has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def suggest_invalid_syntax(value, frame, groups):
        """Get suggestions in case of INVALID_SYNTAX error."""
        del frame, groups  # unused param
        alternatives = {
            '<>': '!=',
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 suggest_attribute_synonyms has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def suggest_attribute_synonyms(attribute, attributes):
        """Suggest that a method with a similar meaning was used.
    
        Example: 'lst.add(e)' -> 'lst.append(e)'.
        """
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 register_suggestion_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def register_suggestion_for(error_type, regex):
        """Decorator to register a function to be called to get suggestions.
    
        Parameters correspond to the fact that the registration is done for a
        specific error type and if the error message matches a given regex
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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 get_func_by_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_func_by_name(func_name, frame):
        """Get the function with the given name in the frame."""
        # TODO: Handle qualified names such as dict.get
        # Dirty workaround is to remove everything before the last '.'
        func_name = func_name.split('.')[-1]
    Severity: Minor
    Found in didyoumean/didyoumean_internal.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

    @register_suggestion_for(TypeError, re.UNEXPECTED_KEYWORDARG4_RE)
    def suggest_unexpected_keywordarg4(value, frame, groups):
        """Get suggestions in case of UNEXPECTED_KEYWORDARG4 error."""
        del value  # unused param
        kw_arg, func_name = groups
    Severity: Major
    Found in didyoumean/didyoumean_internal.py and 1 other location - About 1 hr to fix
    didyoumean/didyoumean_internal.py on lines 696..701

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

    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

    @register_suggestion_for(TypeError, re.UNEXPECTED_KEYWORDARG_RE)
    def suggest_unexpected_keywordarg(value, frame, groups):
        """Get suggestions in case of UNEXPECTED_KEYWORDARG error."""
        del value  # unused param
        func_name, kw_arg = groups
    Severity: Major
    Found in didyoumean/didyoumean_internal.py and 1 other location - About 1 hr to fix
    didyoumean/didyoumean_internal.py on lines 704..709

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

    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

    @register_suggestion_for(TypeError, re.NOT_CALLABLE_RE)
    def suggest_not_callable(value, frame, groups):
        """Get suggestions in case of NOT_CALLABLE error."""
        del value  # unused param
        type_str, = groups
    Severity: Major
    Found in didyoumean/didyoumean_internal.py and 1 other location - About 1 hr to fix
    didyoumean/didyoumean_internal.py on lines 562..567

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

    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

    @register_suggestion_for(TypeError, re.UNSUBSCRIPTABLE_RE)
    def suggest_unsubscriptable(value, frame, groups):
        """Get suggestions in case of UNSUBSCRIPTABLE error."""
        del value  # unused param
        type_str, = groups
    Severity: Major
    Found in didyoumean/didyoumean_internal.py and 1 other location - About 1 hr to fix
    didyoumean/didyoumean_internal.py on lines 570..575

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

    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