andry81/tacklelib

View on GitHub

Showing 58 of 64 total issues

Function __init__ has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def __init__(self, appname, flag='c', mode=0o666, keyencoding='utf-8',
                 serialize=True, app_cache_dir=None):
        """Initialize a :class:`FileCache` object."""
        if not isinstance(flag, str):
            raise TypeError("flag must be str not '{}'".format(type(flag)))
Severity: Minor
Found in python_patches/fcache/cache.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 tkl_get_method_class has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def tkl_get_method_class(x, from_module = None):
  if inspect.ismethod(x):
    for cls in inspect.getmro(x.__self__.__class__):
      if cls.__dict__.get(x.__name__) is x:
        return cls
Severity: Minor
Found in python/tacklelib/tacklelib.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 tkl_classcopy has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def tkl_classcopy(x, from_globals, to_globals):
  if not inspect.isclass(x):
    raise Exception('x must be a class: ' + type(x))

  cls_copy = type(x.__name__, x.__bases__, dict(x.__dict__))
Severity: Minor
Found in python/tacklelib/tacklelib.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 tkl_get_stack_frame_module_by_offset has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def tkl_get_stack_frame_module_by_offset(skip_stack_frames = 0, use_last_frame_on_out_of_stack = False):
  skip_frame_index = skip_stack_frames + 1;

  # search for the first module in the stack
  last_stack_frame = stack_frame = inspect.currentframe()
Severity: Minor
Found in python/tacklelib/tacklelib.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 tkl_import_module has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def tkl_import_module(dir_path, module_file_name, ref_module_name = None, inject_attrs = {}, prefix_exec_module_pred = None, skip_stack_frames = 0, reimport_if_being_imported = False):
  if not ref_module_name is None and ref_module_name == '':
    raise Exception('ref_module_name should either be None or not empty string')

  module_file_path = os.path.normcase(os.path.abspath(os.path.join(dir_path, module_file_name))).replace('\\', '/')
Severity: Minor
Found in python/tacklelib/tacklelib.py - About 1 hr to fix

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

        def rename(src, dst):
            # Try atomic or pseudo-atomic rename
            if _rename(src, dst):
                return
            # Fall back to "move away and replace"
    Severity: Minor
    Found in python_patches/fcache/posixemulation.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 load has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def load(self, yaml_dict):
        if not isinstance(yaml_dict, dict):
          raise Exception('yaml_dict is not a dictionary object')
    
        if len(self.unexpanded_stack) == 0:
    Severity: Minor
    Found in python/tacklelib/tacklelib.yaml.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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self, appname, flag = 'c', mode = 438, keyencoding = 'utf-8', serialize = True, app_cache_dir = None, no_logger_warnings = True):
    Severity: Major
    Found in python/tacklelib/tacklelib.cache.py - About 50 mins to fix

      Function __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def __init__(self, mode = 'r', buffering = -1, encoding = None, errors = None, newline = None, closefd = True, opener = None):
      Severity: Major
      Found in python/tacklelib/tacklelib.io.py - About 50 mins to fix

        Function tkl_import_module has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def tkl_import_module(dir_path, module_file_name, ref_module_name = None, inject_attrs = {}, prefix_exec_module_pred = None, skip_stack_frames = 0, reimport_if_being_imported = False):
        Severity: Major
        Found in python/tacklelib/tacklelib.py - About 50 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      if expand_undefined_var_to_value is None:
                        expanded_value += out_value[prev_match_index:m.start()] + expand_undefined_var_to_prefix + m.group(1) + expand_undefined_var_to_suffix
                      else:
                        expanded_value += out_value[prev_match_index:m.start()] + expand_undefined_var_to_prefix + expand_undefined_var_to_value + expand_undefined_var_to_suffix
                    else:
          Severity: Major
          Found in python/tacklelib/tacklelib.yaml.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      for url in urls:
                        if not is_file_path_printed:
                          print('{0}:'.format(file_path))
                          is_file_path_printed = True
            
            Severity: Major
            Found in python/tacklelib/tools/list_urls_in_files.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        if is_to_module:
                          setattr(to, from_key, to_value)
                        else:
                          to[from_key] = to_value
                      else:
              Severity: Major
              Found in python/tacklelib/tacklelib.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if 'nomergemodule' in target_module_attrs and target_module_attrs['nomergemodule']:
                            raise Exception('attempt to merge the module content to the existed module has been declared as not mergable: ' + to_value.__name__)
                
                Severity: Major
                Found in python/tacklelib/tacklelib.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            if qualname is None or isinstance(qualname, str):
                              return tkl_classcopy(x, from_globals, to_globals)
                  
                  Severity: Major
                  Found in python/tacklelib/tacklelib.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                              if from_value.__name__ not in packaged_modules and \
                                 (not ignore_merge_imported_modules or from_value.__file__.replace('\\', '/') not in imported_modules_by_file_path):
                                #print('mergemodule: ->', from_.__name__, '->', from_key, id(from_value), id(to_value), type(from_value), type(to_value))
                                if not inspect.ismodule(to_value):
                                  # replace by a module instance, based on: https://stackoverflow.com/questions/11170949/how-to-make-a-copy-of-a-python-module-at-runtime/11173076#11173076
                    Severity: Major
                    Found in python/tacklelib/tacklelib.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                    if retry_count % 10 == 0:
                                      # give to scheduler a break
                                      time.sleep(0.02)
                                    continue
                      Severity: Major
                      Found in python/tacklelib/tacklelib.cache.py - About 45 mins to fix

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

                            def __init__(self, appname, flag='c', mode=0o666, keyencoding='utf-8',
                        Severity: Minor
                        Found in python_patches/fcache/cache.py - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                    if not is_module_ref_already_exist:
                                      raise Exception('The module reference must already exist as a module before the import: ' + import_module_name)
                          
                          Severity: Major
                          Found in python/tacklelib/tacklelib.py - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                        if var_value is None: 
                                          if not search_in_expand_dict_at_second is None:
                                            var_value = search_in_expand_dict_at_second.get(var_name)
                                            if var_value is None:
                                              if not search_by_pred_at_third is None:
                            Severity: Major
                            Found in python/tacklelib/tacklelib.yaml.py - About 45 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language