ionelmc/python-aspectlib

View on GitHub
src/aspectlib/__init__.py

Summary

Maintainability
F
1 wk
Test Coverage

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

    def __call__(self, cutpoint_function):
        if isasyncfunction is not None and isasyncfunction(cutpoint_function):
            assert isasyncgenfunction(cutpoint_function) or iscoroutinefunction(cutpoint_function)

            async def advising_asyncgenerator_wrapper_py35(*args, **kwargs):
Severity: Minor
Found in src/aspectlib/__init__.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

Function weave_class has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
Open

def weave_class(
    klass, aspect, methods=NORMAL_METHODS, subclasses=True, lazy=False, owner=None, name=None, aliases=True, bases=True, bag=BrokenBag
):
    """
    Low-level weaver for classes.
Severity: Minor
Found in src/aspectlib/__init__.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 606 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import builtins
import re
import sys
import warnings
from collections import deque
Severity: Major
Found in src/aspectlib/__init__.py - About 1 day to fix

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

    def weave(target, aspects, **options):
        """
        Send a message to a recipient
    
        Args:
    Severity: Minor
    Found in src/aspectlib/__init__.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

    Function patch_module has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def patch_module(module, name, replacement, original=UNSPECIFIED, aliases=True, location=None, **_bogus_options):
        """
        Low-level attribute patcher.
    
        :param module module: Object to patch.
    Severity: Minor
    Found in src/aspectlib/__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 weave_instance has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def weave_instance(instance, aspect, methods=NORMAL_METHODS, lazy=False, bag=BrokenBag, **options):
        """
        Low-level weaver for instances.
    
        .. warning:: You should not use this directly.
    Severity: Minor
    Found in src/aspectlib/__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 weave_class has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def weave_class(
    Severity: Major
    Found in src/aspectlib/__init__.py - About 1 hr to fix

      Function _find_super_classes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def _find_super_classes(klass):
          if hasattr(klass, '__mro__'):
              for k in klass.__mro__:
                  yield k
          else:
      Severity: Minor
      Found in src/aspectlib/__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 _rewrap_method has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def _rewrap_method(func, klass, aspect):
          if isinstance(func, staticmethod):
              if hasattr(func, '__func__'):
                  return staticmethod(_checked_apply(aspect, func.__func__))
              else:
      Severity: Minor
      Found in src/aspectlib/__init__.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 patch_module has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def patch_module(module, name, replacement, original=UNSPECIFIED, aliases=True, location=None, **_bogus_options):
      Severity: Major
      Found in src/aspectlib/__init__.py - About 50 mins to fix

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

        def weave_module(module, aspect, methods=NORMAL_METHODS, lazy=False, bag=BrokenBag, **options):
        Severity: Minor
        Found in src/aspectlib/__init__.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              for attr, func in sklass.__dict__.items():
                                  if method_matches(attr) and attr not in original and attr not in super_original:
                                      if isroutine(func):
                                          logdebug("@ patching attribute %r (from superclass: %s, original: %r).", attr, sklass.__name__, func)
                                          setattr(klass, attr, _rewrap_method(func, sklass, aspect))
          Severity: Major
          Found in src/aspectlib/__init__.py - About 45 mins to fix

            Function weave_module has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            def weave_module(module, aspect, methods=NORMAL_METHODS, lazy=False, bag=BrokenBag, **options):
                """
                Low-level weaver for "whole module weaving".
            
                .. warning:: You should not use this directly.
            Severity: Minor
            Found in src/aspectlib/__init__.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 weave_instance has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def weave_instance(instance, aspect, methods=NORMAL_METHODS, lazy=False, bag=BrokenBag, **options):
            Severity: Minor
            Found in src/aspectlib/__init__.py - About 45 mins to fix

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

              def patch_module_function(module, target, aspect, force_name=None, bag=BrokenBag, **options):
              Severity: Minor
              Found in src/aspectlib/__init__.py - About 45 mins to fix

                Consider simplifying this complex logical expression.
                Open

                    if name and getattr(builtins, name, None) is target:
                        if bag.has(target):
                            return Nothing
                        return patch_module_function(builtins, target, aspects, **options)
                    elif PY3 and ismethod(target):
                Severity: Major
                Found in src/aspectlib/__init__.py - About 40 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return weave_instance(target, aspects, **options)
                  Severity: Major
                  Found in src/aspectlib/__init__.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return mimic(advising_function_wrapper, cutpoint_function)
                    Severity: Major
                    Found in src/aspectlib/__init__.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return patch_module_function(builtins, target, aspects, **options)
                      Severity: Major
                      Found in src/aspectlib/__init__.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return patch_module_function(owner, obj, aspects, force_name=name, **options)
                        Severity: Major
                        Found in src/aspectlib/__init__.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return Nothing
                          Severity: Major
                          Found in src/aspectlib/__init__.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return _checked_apply(aspect, func)
                            Severity: Major
                            Found in src/aspectlib/__init__.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return weave(obj, aspects, **options)
                              Severity: Major
                              Found in src/aspectlib/__init__.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return weave_class(target, aspects, **options)
                                Severity: Major
                                Found in src/aspectlib/__init__.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                              return mimic(advising_generator_wrapper_py35, cutpoint_function)
                                  Severity: Major
                                  Found in src/aspectlib/__init__.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                            return patch_module(owner, name, _checked_apply(aspects, func), func, **options)
                                    Severity: Major
                                    Found in src/aspectlib/__init__.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                  return Nothing
                                      Severity: Major
                                      Found in src/aspectlib/__init__.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                return Rollback(lambda: delattr(inst, name))
                                        Severity: Major
                                        Found in src/aspectlib/__init__.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                  return weave_module(target, aspects, **options)
                                          Severity: Major
                                          Found in src/aspectlib/__init__.py - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                        return Nothing
                                            Severity: Major
                                            Found in src/aspectlib/__init__.py - About 30 mins to fix

                                              There are no issues that match your filters.

                                              Category
                                              Status