alot/ui.py

Summary

Maintainability
F
3 days
Test Coverage

File ui.py has 655 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright (C) 2011-2012  Patrick Totzke <patricktotzke@gmail.com>
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import logging
import os
Severity: Major
Found in alot/ui.py - About 1 day to fix

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

        def _input_filter(self, keys, raw):
            """
            handles keypresses.
            This function gets triggered directly by class:`urwid.MainLoop`
            upon user input and is supposed to pass on its `keys` parameter
    Severity: Minor
    Found in alot/ui.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

    UI has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class UI:
        """
        This class integrates all components of alot and offers
        methods for user interaction like :meth:`prompt`, :meth:`notify` etc.
        It handles the urwid widget tree and mainloop (we use asyncio) and is
    Severity: Minor
    Found in alot/ui.py - About 2 hrs to fix

      Function __init__ has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, dbman, initialcmdline):
              """
              :param dbman: :class:`~alot.db.DBManager`
              :param initialcmdline: commandline applied after setting up interface
              :type initialcmdline: str
      Severity: Major
      Found in alot/ui.py - About 2 hrs to fix

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

            def notify(self, message, priority='normal', timeout=0, block=False):
                """
                opens notification popup.
        
                :param message: message to print
        Severity: Minor
        Found in alot/ui.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

        Avoid deeply nested control flow statements.
        Open

                                if self._alarm is not None:
                                    self.mainloop.remove_alarm(self._alarm)
                                self._alarm = self.mainloop.set_alarm_in(
        Severity: Major
        Found in alot/ui.py - About 45 mins to fix

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

              def choice(self, message, choices=None, select=None, cancel=None,
          Severity: Minor
          Found in alot/ui.py - About 45 mins to fix

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

                def buffer_focus(self, buf, redraw=True):
                    """focus given :class:`~alot.buffers.Buffer`."""
            
                    # call pre_buffer_focus hook
                    prehook = settings.get_hook('pre_buffer_focus')
            Severity: Minor
            Found in alot/ui.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 prompt has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def prompt(self, prefix, text='', completer=None, tab=0, history=None):
            Severity: Minor
            Found in alot/ui.py - About 35 mins to fix

              Function update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def update(self, redraw=True):
                      """redraw interface"""
                      # get the main urwid.Frame widget
                      mainframe = self.root_widget.original_widget
              
              
              Severity: Minor
              Found in alot/ui.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 get_deep_focus has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_deep_focus(self, startfrom=None):
                      """return the bottom most focussed widget of the widget tree"""
                      if not startfrom:
                          startfrom = self.current_buffer
                      if 'get_focus' in dir(startfrom):
              Severity: Minor
              Found in alot/ui.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

              FIXME found
              Open

                      # FIXME: What are we guarding for here? We don't mention that None is
              Severity: Minor
              Found in alot/ui.py by fixme

              Ambiguous variable name 'l'
              Open

                      for l in messages:
              Severity: Minor
              Found in alot/ui.py by pep8

              Never use the characters 'l', 'O', or 'I' as variable names.

              In some fonts, these characters are indistinguishable from the
              numerals one and zero. When tempted to use 'l', use 'L' instead.
              
              Okay: L = 0
              Okay: o = 123
              Okay: i = 42
              E741: l = 0
              E741: O = 123
              E741: I = 42
              
              Variables can be bound in several other contexts, including class
              and function definitions, 'global' and 'nonlocal' statements,
              exception handlers, and 'with' and 'for' statements.
              In addition, we have a special handling for function parameters.
              
              Okay: except AttributeError as o:
              Okay: with lock as L:
              Okay: foo(l=12)
              Okay: for a in foo(l=12):
              E741: except AttributeError as O:
              E741: with lock as l:
              E741: global I
              E741: nonlocal l
              E741: def foo(l):
              E741: def foo(l=12):
              E741: l = foo(l=12)
              E741: for l in range(10):
              E742: class I(object):
              E743: def l(x):

              There are no issues that match your filters.

              Category
              Status