ionelmc/python-hunter

View on GitHub

Showing 67 of 67 total issues

File actions.py has 758 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# ruff: noqa: B008
import collections
import opcode
import os
import threading
Severity: Major
Found in src/hunter/actions.py - About 1 day to fix

    File predicates.py has 718 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import collections
    import inspect
    import re
    from itertools import chain
    
    
    Severity: Major
    Found in src/hunter/predicates.py - About 1 day to fix

      Function __call__ has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
      Open

          def __call__(self, event):
              """
              Handles the event.
              """
              result = self.condition(event)
      Severity: Minor
      Found in src/hunter/predicates.py - About 1 day 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

      File __init__.py has 447 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import atexit
      import functools
      import inspect
      import os
      import sys
      Severity: Minor
      Found in src/hunter/__init__.py - About 6 hrs to fix

        Function safe_repr has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
        Open

        def safe_repr(obj, maxdepth=5):
            if not maxdepth:
                return '...'
            obj_type = type(obj)
            obj_type_type = type(obj_type)
        Severity: Minor
        Found in src/hunter/util.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 __init__ has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, **query):
                query_eq = {}
                query_startswith = {}
                query_endswith = {}
                query_in = {}
        Severity: Minor
        Found in src/hunter/predicates.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 __call__ has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
        Open

            def __call__(self, event):
                """
                Handle event and print filename, line number and source code. If event.kind is a `return` or `exception` also
                prints values.
                """
        Severity: Minor
        Found in src/hunter/actions.py - About 4 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 __call__ has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

            def __call__(self, event):
                """
                Handles event. Returns True if all criteria matched.
                """
                for key, value in self.query_eq:
        Severity: Minor
        Found in src/hunter/predicates.py - About 4 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 __call__ has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

            def __call__(self, event):
                if self.max_backlog:
                    detached_event = event.detach(self.try_repr)
                    self.backlog.append(detached_event)
                else:
        Severity: Minor
        Found in src/hunter/actions.py - About 4 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

        File event.py has 343 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import linecache
        from functools import partial
        from os.path import basename
        from os.path import exists
        from os.path import splitext
        Severity: Minor
        Found in src/hunter/event.py - About 4 hrs to fix

          Function Q has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
          Open

          def Q(*predicates, **query):
              """
              Helper that handles situations where :class:`hunter.predicates.Query` objects (or other callables)
              are passed in as positional arguments - it conveniently converts those to a
              :class:`hunter.predicates.And` predicate.
          Severity: Minor
          Found in src/hunter/__init__.py - About 3 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 __call__ has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              def __call__(self, event):
                  """
                  Handle event and print the specified variables.
                  """
                  first = True
          Severity: Minor
          Found in src/hunter/actions.py - About 2 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

          Event has 21 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class Event:
              """
              A wrapper object for Frame objects. Instances of this are passed to your custom functions or predicates.
          
              Provides few convenience properties.
          Severity: Minor
          Found in src/hunter/event.py - About 2 hrs to fix

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

                def __call__(self, event):
                    """
                    Handle event and print the specified variables.
                    """
                    first = True
            Severity: Minor
            Found in src/hunter/actions.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 wrap has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            def wrap(function_to_trace=None, **trace_options):
                """
                Functions decorated with this will be traced.
            
                Use ``local=True`` to only trace local code, eg::
            Severity: Minor
            Found in src/hunter/__init__.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 function_object has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def function_object(self):
                    """
                    The function instance.
            
                    .. warning:: Use with prudence.
            Severity: Minor
            Found in src/hunter/event.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 _prepare_config has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            def _prepare_config(*args, **kwargs):
                _default_config.clear()
                _default_config.update((key.lower(), val) for key, val in kwargs.items())
                options = {}
                predicates = []
            Severity: Minor
            Found in src/hunter/__init__.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 _flatten has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            def _flatten(cls, predicate, *predicates):
                if not predicates:
                    return predicate
                else:
                    all_predicates = []
            Severity: Minor
            Found in src/hunter/__init__.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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            class DevelopWithPTH(develop):
                def run(self):
                    super().run()
                    self.copy_file(pth_file, str(Path(self.install_dir, 'hunter.pth')))
            Severity: Major
            Found in setup.py and 1 other location - About 1 hr to fix
            setup.py on lines 37..40

            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

            class BuildWithPTH(build):
                def run(self):
                    super().run()
                    self.copy_file(pth_file, str(Path(self.build_lib, 'hunter.pth')))
            Severity: Major
            Found in setup.py and 1 other location - About 1 hr to fix
            setup.py on lines 60..63

            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

            Severity
            Category
            Status
            Source
            Language